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

其他回答

这里有一个解决方案(单用户):

GOROOT=$HOME/.local # your go executable is in $GOROOT/bin
GOPATH=$HOME/.gopath
PATH=$GOROOT/bin:$GOPATH/bin:$PATH

如果你把。gopath改成。Go, Go会报错。

我希望他们能像运货员那样,把所有东西都放在一个地方。

在osx中,我安装了brew,下面是适合我的设置

GOPATH="$HOME/my_go_work_space" //make sure you have this folder created

GOROOT="/usr/local/Cellar/go/1.10/libexec"

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

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

(这是针对Fedora 20)

如上所述:

GOPATH环境变量指定您的 工作区。

对于Windows,这对我来说是有效的(在Ms-dos窗口中):

set GOPATH=D:\my_folder_for_go_code\

这将创建一个Ms-dos识别的GOPATH变量,使用如下:

cd %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.