简体   繁体   English

如何在 Ubuntu 上的 go 1.11 中设置 GOPATH 环境变量? 我必须编辑什么文件?

[英]how do I SET the GOPATH environment variable in go 1.11 on Ubuntu? What file must I edit?

ubuntu@ubuntu:~/.work/src/github.hpe.com/hybridpoc/marketplace-terraform-tf-broker$ go run main.go
main.go:10:2: cannot find package "github.hpe.com/hybridpoc/marketplace-terraform-tf-broker/broker/github" in any of:
        /home/ubuntu/go/src/github.hpe.com/hybridpoc/marketplace-terraform-tf-broker/broker/github (from $GOROOT)
        /home/ubuntu/work/src/github.hpe.com/hybridpoc/marketplace-terraform-tf-broker/broker/github (from $GOPATH)
main.go:11:2: cannot find package "github.hpe.com/hybridpoc/marketplace-terraform-tf-broker/handlers" in any of:
        /home/ubuntu/go/src/github.hpe.com/hybridpoc/marketplace-terraform-tf-broker/handlers (from $GOROOT)
        /home/ubuntu/work/src/github.hpe.com/hybridpoc/marketplace-terraform-tf-broker/handlers (from $GOPATH)

This question seems to be about setting environment variables, not about the Go programming language.这个问题似乎是关于设置环境变量,而不是关于 Go 编程语言。

As such, there are many answers.因此,有很多答案。 For example this ask.ubuntu question .例如这个 ask.ubuntu 问题

The easiest way for experimentation is prefixing your commands with NAME=value , for example:最简单的实验方法是在命令前加上NAME=value前缀,例如:

$ GOPATH=/some/path go <command>

Or, if you want to extend it to multiple shell commands within the same session, do:或者,如果您想将其扩展到同一会话中的多个 shell 命令,请执行以下操作:

$ export GOPATH=/some/path
$ go <command>

Once these work well, add the GOPATH setting to your ~/.bashrc file so that future sessions will find it without needing to export一旦这些工作正常,将GOPATH设置添加到您的~/.bashrc文件,以便以后的会话无需export即可找到它

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM