GOPATH 和 GOROOT 的值应该是什么? [英] What should be the values of GOPATH and GOROOT?

查看:34
本文介绍了GOPATH 和 GOROOT 的值应该是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试像这样安装 doozer:

$ goinstall github.com/ha/doozer

我收到这些错误.

<块引用>

goinstall: os: go/build: package 在本地找不到goinstall: fmt: go/build: 本地找不到包goinstall: io: go/build: 本地找不到包goinstall:反映:go/build:在本地找不到包goinstall:数学:go/build:在本地找不到包goinstall: rand: go/build: 本地找不到包goinstall: url: go/build: 本地找不到包goinstall: net: go/build: 本地找不到包goinstall:同步:go/build:在本地找不到包goinstall:运行时:go/build:在本地找不到包goinstall:strings:go/build:在本地找不到包goinstall:排序:go/build:在本地找不到包goinstall: strconv: go/build: 本地找不到包goinstall:字节:go/build:在本地找不到包goinstall: 日志: go/build: 本地找不到包goinstall:编码/二进制:go/build:在本地找不到包

解决方案

GOPATH 讨论 cmd/go 文档中:

<块引用>

GOPATH 环境变量列出了查找 Go 代码的位置.在Unix,该值是一个冒号分隔的字符串.在 Windows 上,该值为分号分隔的字符串.在计划 9 中,该值是一个列表.

GOPATH 必须设置为在外部获取、构建和安装包标准的 Go 树.

GOROOT安装说明中讨论:

<块引用>

Go 二进制发行版假定它们将安装在/usr/local/go(或Windows下的c:Go),但可以安装Go 工具到不同的位置.在这种情况下,您必须设置GOROOT 环境变量指向它所在的目录已安装.

例如,如果您安装了转到您的主目录,您应该添加以下命令$HOME/.profile:

export GOROOT=$HOME/go导出路径=$PATH:$GOROOT/bin

注意: GOROOT 仅在安装到自定义位置时必须设置.

(Chris Bunch 的回答 的更新版本.)

I'm trying to install doozer like this:

$ goinstall github.com/ha/doozer

I get these errors.

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 is discussed 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.

GOROOT is discussed in the 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.

(updated version of Chris Bunch's answer.)

这篇关于GOPATH 和 GOROOT 的值应该是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆