我试图像这样安装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.

其他回答

GOPATH的讨论如下:

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

这里讨论的是GOROOT:

$GOROOT Go树的根,通常是$HOME/ Go。默认为 目录的父目录。Bash运行。如果你选择不去的话 设置$GOROOT时,必须运行gomake而不是make或gmake 使用传统的makefile开发Go程序。

GOPATH不应该指向Go安装,而是指向您的工作空间(参见https://golang.org/doc/code.html#GOPATH)。当你使用go get或go install安装某个包时,它会落在GOPATH中。这就是为什么它警告你,你绝对不希望从互联网随机包被转储到你的正式安装。

具体到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.

安装Go lang之后,GOROOT是安装的根目录。

当我在Windows C:\目录中分解Go Lang二进制时,我的GOROOT应该是C:\ Go。 如果安装Windows安装程序,它可能是C:\Program Files\go(或C:\Program Files (x86)\ go, 64位包)

 GOROOT = C:\go

而我的GOPATH是Go lang源代码或工作区的位置。

如果我的Go lang源代码位于C:\Users\\GO_Workspace,那么你的GOPATH将如下所示:

 GOPATH = C:\Users\<xyz>\GO_Workspace

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

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

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