欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

GOPATH和GOROOT的值应该是多少?

程序员文章站 2022-06-03 22:45:56
...

本文翻译自:What should be the values of GOPATH and GOROOT?

I'm trying to install doozer like this: 我正在尝试像这样安装doozer

$ 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 

#1楼

参考:https://stackoom.com/question/xrsG/GOPATH和GOROOT的值应该是多少


#2楼

GOPATH is discussed in the cmd/go documentation : cmd/go文档中讨论了GOPATH

The GOPATH environment variable lists places to look for Go code. GOPATH环境变量列出了查找Go代码的位置。 On Unix, the value is a colon-separated string. 在Unix上,该值是用冒号分隔的字符串。 On Windows, the value is a semicolon-separated string. 在Windows上,该值为分号分隔的字符串。 On Plan 9, the value is a list. 在计划9中,该值是一个列表。

GOPATH must be set to get, build and install packages outside the standard Go tree. 必须将GOPATH设置为在标准Go树之外获取,构建和安装软件包。

GOROOT is discussed in the installation instructions : 安装说明中讨论了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. Go二进制发行版假定它们将安装在/usr/local/go (或在Windows下为c:\\Go )中,但是可以将Go工具安装到其他位置。 In this case you must set the GOROOT environment variable to point to the directory in which it was installed. 在这种情况下,您必须将GOROOT环境变量设置为指向其安装目录。

For example, if you installed Go to your home directory you should add the following commands to $HOME/.profile : 例如,如果您安装了转到主目录,则应将以下命令添加到$HOME/.profile

 export GOROOT=$HOME/go export PATH=$PATH:$GOROOT/bin 

Note: GOROOT must be set only when installing to a custom location. 注意:只有在安装到自定义位置时,才必须设置GOROOT

(updated version of Chris Bunch's answer .) 克里斯·邦奇答案的更新版本。)


#3楼

I read the go help gopath docs and was still incredibly confused, but found this little nugget from another go doc page: 我阅读了go help gopath文档,仍然感到非常困惑,但是在另一个go doc页面上发现了这个小块:

The GOPATH environment variable specifies the location of your workspace. GOPATH环境变量指定工作空间的位置。 It is likely the only environment variable you'll need to set when developing Go code. 在开发Go代码时,很可能需要设置唯一的环境变量。

http://golang.org/doc/code.html#GOPATH http://golang.org/doc/code.html#GOPATH


#4楼

As mentioned above: 正如刚才提到的:

The GOPATH environment variable specifies the location of your workspace. GOPATH环境变量指定工作空间的位置。

For Windows , this worked for me (in Ms-dos window): 对于Windows ,这对我有用(在Ms-dos窗口中):

set GOPATH=D:\my_folder_for_go_code\

This creates a GOPATH variable that Ms-dos recognizes when used as follows: 这将创建一个Ms-dos可以识别的GOPATH变量,如下所示:

cd %GOPATH%

#5楼

Here is a my simple setup: 这是我的简单设置:

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 are set as following: 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

So, in short: 因此,简而言之:

GOROOT is for compiler/tools that comes from go installation. GOROOT用于来自go安装的编译器/工具。
GOPATH is for your own go projects / 3rd party libraries (downloaded with "go get"). GOPATH用于您自己的go项目/第3方库(通过“ go get”下载)。


#6楼

If you are using the distro go, you should point to where the include files are, for example: 如果使用发行版,则应指向包含文件的位置,例如:

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

(This is for Fedora 20) (这是针对Fedora 20的)

相关标签: go gopath