Goroot
The path to the go language installation, such as/usr/local/go under Mac, is similar to Java_home in Java.
Gopath
Gopath represents the address where the code package resides, and can be set more than one.
Assume: Gopath=~/go1:~/go2,goroot=/usr/local/go, the package is referenced in the code: Github.com/bitly/nsq/util
Then: The go program will compile in order to the following directory to find the source code:
~/go1/github.com/bitly/nsq/util
~/go2/github.com/bitly/nsq/util
/usr/local/go/github.com/bitly/nsq/util
If the package is not found in three directories, it will be an error.
PATH
The path to the executable program, which, when executed at the command line, is searched by default in the path specified in paths. For example, under Linux we use the most common LS command, we do not specify the path of the LS command, or switch to the directory where LS is located to execute the command. This is because the executable file of the LS command is in the same directory as the path entry.
After go installs, in the Goroot/bin directory, such as the Mac/usr/local/go/bin directory will have go, Godoc, gofmt three executable commands. To make it easy to use the go build and go install commands when compiling the GO project, you need to add the Goroot/bin directory to the system's path path.
Go related environment variable PATH gopath goroot