This is a creation in Article, where the information may have evolved or changed.
Starting with Go 1.8, if the GOPATH environment variable is empty, go will set a default Gopath environment variable.
When go beginners install go for the first time, they tend to get the error that you had to set a gopath because they forgot to set the GOPATH environment variable. The priority of this requirement is getting higher. For new users of Go, explaining the role of Gopath and directing them to set up Gopath will make it impossible for them to focus on go. Especially sometimes, these people are not going to use the go language to develop, but instead use go get
to download some necessary commands.
Go 1.8 will set the default Gopath. If you do not set the Gopath,go yourself, the default value will be used. The default Gopath is:
- It's in the directory on the Unix-like system.
$HOME/go
- Under Windows System is
%USERPROFILE%\go
Although the default Gopath is already available, it does not solve all the problems:
- We still have to add them
$GOPATH/bin
to the PATH
inside so that they go get
can be run directly through the binaries installed with go install. (The Translator notes: Of course, it is possible to run these programs through an absolute path, but it is more troublesome).
- The Go language developer still needs to understand the role of Gopath and its directory structure.
- If your
GOROOT
path (which is where you let go source) is the same as the default Gopath, and you do not set a default Gopath,go, it is not to set the default gopath for you, because it will confuse the contents of Goroot.
When you have questions, you can run the command go env GOPATH
to check the path of the Gopath. If there is a problem, such as what is said above, go does not automatically generate Gopath, this command will print empty.
Read the original The default Gopath
The original link: "Translation" Gopath default value, reprint please indicate the source!