The default GOPATH
Wed, Dec 14, 2016Go 1.8 will set a default GOPATH if the GOPATH env variable is not set.
The requirement of setting a GOPATH has been a major issue for Go users
who installed the Go tools for the first time and got the
“you have to set a GOPATH” error in their initial experience with the tools.
Explaining the GOPATH is and instructing how to set this env variable were both
distracting new users away from using Go. This was especially true for users who
are not necessarily developing in Go but using go get
to download commands.
Go 1.8 is introducing a default GOPATH. If you don’t set one, the tools will use the default. Default GOPATH is:
- $HOME/go on Unix-like systems
- %USERPROFILE%\go on Windows
Even though you don’t have care about setting this variable, there are few items that still requires your attention.
- Users still need to add $GOPATH/bin into their PATH to run binaries installed by
go get
andgo install
. - The users who are developing with the Go language still need to understand that the presence of GOPATH, its location and its structure.
- If your GOROOT (the location where you checkout the Go’s source code) is the default GOPATH and if you don’t have a GOPATH set, the tools will reject to use the default GOPATH not to corrupt your GOROOT.
You still may prefer to set a custom GOPATH if the default is not working for you.
If a custom GOPATH is set, go env GOPATH
will report its value.