我试图像这样安装doozer:

$ goinstall github.com/ha/doozer

我得到这些错误。

goinstall: os: go/build: package could not be found locally goinstall: fmt: go/build: package could not be found locally goinstall: io: go/build: package could not be found locally goinstall: reflect: go/build: package could not be found locally goinstall: math: go/build: package could not be found locally goinstall: rand: go/build: package could not be found locally goinstall: url: go/build: package could not be found locally goinstall: net: go/build: package could not be found locally goinstall: sync: go/build: package could not be found locally goinstall: runtime: go/build: package could not be found locally goinstall: strings: go/build: package could not be found locally goinstall: sort: go/build: package could not be found locally goinstall: strconv: go/build: package could not be found locally goinstall: bytes: go/build: package could not be found locally goinstall: log: go/build: package could not be found locally goinstall: encoding/binary: go/build: package could not be found locally


当前回答

具体到GOROOT, Go 1.9会自动将其设置到其安装路径。 即使你安装了多个Go,调用1.9。xone将GOROOT设置为/path/到/go/1.9(之前,如果没有设置,它假设默认路径为/usr/local/go或c:\ go)。

参见CL Go Review 53370:

The go tool will now use the path from which it was invoked to attempt to locate the root of the Go install tree. This means that if the entire Go installation is moved to a new location, the go tool should continue to work as usual. This may be overriden by setting GOROOT in the environment, which should only be done in unusual circumstances. Note that this does not affect the result of the runtime.GOROOT() function, which will continue to report the original installation location; this may be fixed in later releases.

其他回答

我不得不追加

export GOROOT=/usr/local/Cellar/go/1.10.1/libexec

致我的~/。在Mac OS X上使用bash_profile

如果你正在使用发行版go,你应该指向包含文件的位置,例如:

$ rpm -ql golang | grep include
/usr/lib/golang/include

(这是针对Fedora 20)

答案很多,但没有实质内容,就像机器人对系统中的内容进行剪切和粘贴。不需要将GOROOT设置为环境变量。但是,有必要设置GOPATH环境变量,如果没有设置,则默认为${HOME}/go/ folder。

您必须注意的是PATH环境变量,因为这个变量可以改变您的go版本。不是GOROOT !忘记GOROOT。

现在,如果你切换或更改到一个新的go版本,你下载的包将使用默认的$HOME/go文件夹,它将与你之前的go版本混合。这可不太好。

因此,这就是需要定义GOPATH的地方,以便隔离新go版本的下载包。

总之,忘掉GOROOT吧。多想想GOPATH。

您不需要显式地设置GOROOT(现代版本的Go可以根据您运行的Go二进制文件的位置自行确定)。

另外,当尝试使用vgo工作时,得到了跟随错误:

go: modules disabled inside GOPATH/src by GO111MODULE=auto; see 'go help modules'

删除GOROOT,更新我的GOPATH和导出GO111MODULE=“on”解决了这个问题。

看这里

GOPATH可以设置为一个以冒号分隔的路径列表,其中可以找到Go代码、包对象和可执行文件。 设置GOPATH使用goinstall在Go树之外构建和安装自己的代码和外部库(并避免编写makefile)。

我读了go help gopath文档,仍然非常困惑,但从另一个go文档页面中发现了这个小块:

GOPATH环境变量指定工作空间的位置。它可能是开发Go代码时需要设置的唯一环境变量。

http://golang.org/doc/code.html#GOPATH