go - GOPATH 和 GOROOT 的值应该是多少?

标签 go gopath

我正在尝试安装 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

最佳答案

GOPATH 已讨论 in the cmd/go documentation :

The GOPATH environment variable lists places to look for Go code. On Unix, the value is a colon-separated string. On Windows, the value is a semicolon-separated string. On Plan 9, the value is a list.

GOPATH must be set to get, build and install packages outside the standard Go tree.

GOROOTthe installation instructions 中讨论:

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.

(Chris Bunch's answer 的更新版本。)

关于go - GOPATH 和 GOROOT 的值应该是多少?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49738719/

相关文章:

golang 运行时包从构建它的系统设置文件路径

Golang,带有指针和接口(interface)的用例

go - 为 Go 测试设置环境变量

sockets - 如何从Golang中的socket io获取ip地址

go - 如何解决import-local-package问题 : GOPATH is ignored, only GOROOT才生效

go - 无法从 $GOROOT 和 $GOPATH 中找到包

struct - 如何有效地将 goroutine 中分配的结构通过 channel 传递回主例程?

json - 进行 json 解码时为空字段

macos - 在Mac OS上安装了“go1.13.3.darwin-amd64.pkg”。设置GOPATH,PATH,GOROOT环境变量。但是Go似乎没有安装

git - 使用 git 设置正确的 Golang 目录结构以在自定义包上使用 go build