GOPATH is an environmental variable used to define the location of your workplace directory. It's used by the Go tools for various reasons.
For example:
go get -u github.com/nsf/gocode
- will download the source code and place it at
$GOPATH/src/github.com/nsfs/gocode
- Compile that source code and
place the binary at
$GOPATH/bin
- Place symbol and package information at
$GOPATH/pkg/architecture/github.com/nsfs
The path is also used in other tools:
-
go build github.com/nsf/gocode
go install github.com/nsfs/gocode
github.com/nsfs/gocode
in the above commands is resolved automatically to $GOPATH/src/github.com/nsfs/gocode
and thus you can run these commands without actually being in your workplace (the point of $GOPATH)
The $GOPATH location for your workplace directory can be put anywhere on your machine, but it must minimally have 3 folders (because go get and other tools need these folders).
- bin
- pkg
- src
This environmental variable can be set like any other environmental variable. If you're using go from the Terminal.app, you can set it by opening the file:
vi ~/.bashrc
and then setting it
export GOPATH=~/goworkplace
~/goworkplace
is a location to the workplace directory with those 3 folders. It can be anywhere on your system, such as, ~/Development/goworkplace, ~/Desktop/goworkplace, as long as it has those 3 folders
For information, take a look at this: https://golang.org/doc/code.html