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


当前回答

截至2020年和Go版本1.13+,在Windows中更新GOPATH的最佳方法是在命令提示符中输入:

setx GOPATH C:\mynewgopath

其他回答

安装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

以下是我的简单设置:

directory for go related things: ~/programming/go
directory for go compiler/tools: ~/programming/go/go-1.4
directory for go software      : ~/programming/go/packages

GOROOT、GOPATH、PATH的设置如下:

export GOROOT=/home/user/programming/go/go-1.4
export GOPATH=/home/user/programming/go/packages
export PATH=$PATH:$GOROOT/bin:$GOPATH/bin

所以,简而言之:

GOROOT是编译器/工具,来自go安装。 GOPATH是为你自己的项目/第三方库(下载“go get”)。

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

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

(这是针对Fedora 20)

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

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

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

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

对于所有新手,如果你正在使用Ubuntu,他们可以简单地导出GOPATH=$HOME/go,或者去帮助GOPATH获取更多信息。