Go:使用 -u 命令安装包

Go: Install package with -u command

我正在尝试通过 运行 这个命令

安装 Go 包 (https://github.com/jteeuwen/go-bindata#installation)
go get -u github.com/jteeuwen/go-bindata/...

我收到此错误:

package github.com/jteeuwen/go-bindata/...: cannot download, $GOPATH not set. For more details see: go help gopath

我的GOPATH是用普通方式设置的。我知道这是由 -u 命令引起的...我该如何解决?

这取决于您的 OS,但请确保您的 GOPATH.bashrc 中设置(如 in this question)或至少设置为

export GOPATH=/home/<username>/go

这样,其他进程(如 go get)将继承该变量。

在 Windows 上,您将在用户环境变量中声明该变量。

检查已设置的内容 ("Print Go environment information"):

go env

如果变量已经设置,但是 go get -u 仍然失败,那么这可能类似于 issue 42:

Your issue is that you have installed go to a location that requires privilege escalation to install to.

同时检查您的 GOROOT and where go is installed