gopath
As written in How to Write Go Code,
如《 如何编写Go代码》中所述 ,
Go programmers typically keep all their Go code in a single workspace.
Go程序员通常将所有Go代码保存在一个工作区中。
A workspace contains many version control repositories (managed by Git, for example).
工作区包含许多版本控制存储库(例如,由Git管理)。
Each repository contains one or more packages.
每个存储库包含一个或多个软件包。
The GOPATH
environment variable specifies the location of your workspace. That’s where you find the Go tools, where you develop and where you install 3rd party packages and binaries.
GOPATH
环境变量指定工作空间的位置。 在这里可以找到Go工具,在这里可以开发并在其中安装3rd party软件包和二进制文件。
As of Go 1.8, if you don’t set a GOPATH
, the default will be used. In older releases had to set it explicitly, but for ease of use, a default has been introduced. By default the value of GOPATH
is
从Go 1.8开始,如果您未设置GOPATH
,则将使用默认值。 在较早的版本中,必须明确设置它,但是为了易于使用,引入了默认设置。 默认情况下, GOPATH
值为
$HOME/go
on Unix-like systems$HOME/go
在类似Unix的系统上%USERPROFILE%\go
on Windows在Windows上为
%USERPROFILE%\go
This means that on macOS all your Go code will be put in the /go
folder in your home directory.
这意味着在macOS上,您所有的Go代码都将放在主目录的/go
文件夹中。
This is the most common setup, but you might also choose to use your home directory as GOPATH
.
这是最常见的设置,但是您也可以选择将主目录用作GOPATH
。
Libraries installed using go get
will be put in $GOPATH/src
使用go get
安装的库将放在$GOPATH/src
Commands installed using go get
will be put in $GOPATH/bin
使用go get
安装的命令将放在$GOPATH/bin
Speaking of commands, you need to add $GOPATH/bin
to your PATH
to execute any binary installed in $GOPATH/bin
, or you need to type $GOPATH/bin/the-command
. Add this to your ~/.bash_profile
or ~/.zshrc
(or whatever shell you use) on *nix:
说到命令,您需要将$GOPATH/bin
添加到PATH
以执行安装在$GOPATH/bin
任何二进制文件,或者需要键入$GOPATH/bin/the-command
。 将其添加到* nix上的~/.bash_profile
或~/.zshrc
(或使用的任何shell)中:
export PATH=$GOPATH/bin:$PATH
A quick way to know what is your current GOPATH
is running
一种快速了解您当前运行的GOPATH
方法
go env GOPATH
Changing the GOPATH is easy, add this to your shell config file:
更改GOPATH很容易,将其添加到您的Shell配置文件中:
export GOPATH=$HOME/another-go-path
(Here’s how to set the PATH or GOPATH on Windows)
( 以下是在Windows上设置PATH或GOPATH的方法 )
参考文献 (References)
https://github.com/golang/go/wiki/SettingGOPATH https://golang.org/doc/code.html#GOPATH https://github.com/golang/go/wiki/GOPATH
https://github.com/golang/go/wiki/SettingGOPATH https://golang.org/doc/code.html#GOPATH https://github.com/golang/go/wiki/GOPATH
gopath