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


当前回答

运行go help environment,它有go env命令可以列出的每个环境变量的文档

其他回答

从go 1.8(2017年第二季度)开始,GOPATH将默认设置为$HOME/go

参见第17262期和Rob Pike的评论:

$HOME/go就是这样。 没有唯一的最佳答案,但这是简短而甜蜜的,只有在$HOME/go已经存在的情况下,选择这个名称才会成为一个问题,这只会发生在已经安装了go并且理解GOPATH的专家身上。

在cmd/go文档中讨论了GOPATH:

GOPATH环境变量列出了寻找Go代码的位置。在 Unix,值是一个冒号分隔的字符串。Windows操作系统为 以分号分隔的字符串。在Plan 9中,取值为列表。 必须将GOPATH设置为在外部获取、构建和安装包 标准围棋树。

安装说明中讨论了GOROOT:

The Go binary distributions assume they will be installed in /usr/local/go (or c:\Go under Windows), but it is possible to install the Go tools to a different location. In this case you must set the GOROOT environment variable to point to the directory in which it was installed. For example, if you installed Go to your home directory you should add the following commands to $HOME/.profile: export GOROOT=$HOME/go export PATH=$PATH:$GOROOT/bin Note: GOROOT must be set only when installing to a custom location.

(更新版的克里斯·邦奇的回答。)

第一次运行go env。 如果你看到go没有安装,你可以通过homebrew或包和/或其他方式安装它。 如果您看到输出,那么您的Go已经安装。 它向你展示了所有已设置和未设置的env。

如果你看到GOROOT为空:

在我的电脑上:/usr/local/go/bin/go 然后export GOROOT=/usr/local/go

如果你看到GOPATH为空:

在计算机的任何位置为go项目创建任意目录,在我的例子中是:~/GO_PROJECTS 然后导出GOPATH=~/GO_PROJECTS

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

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

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

你可以使用一个命令:go env GOPATH