The GOPATH environment variable lists places to look for Go code. It defines your workspace. It is likely the only environment variable you’ll need to set when developing Go code.
Official documentation:
Normally the GOPATH is set in your shell profile (one of ~/.bashrc, ~/.bash_profile, etc).
When you install packages and build binaries, the Go tool will look for source code in $GOPATH/src/ followed by a package import path in order to resolve dependencies. More on this shortly.
The GOPATH works like the PATH environment variable, where you can have multiple locations separated by a : (; on Windows).
Some people prefer to use a single path workspace, like GOPATH=/Users/kelly/work/go. Others use multiple paths, like GOPATH=/home/rodolfo/.go-vendor:/home/rodolfo/Dropbox/go:/home/rodolfo/openshift. When using multiple paths, the Go tool will download and install new packages to the first path in the list, while preserving the same path when building existing source code.
Make sure to have a line defining your GOPATH in your ~/.bashrc or equivalent:
export GOPATH=$HOME/go
Pro tip: include also a line to add GOPATH/bin to your PATH, so that you can easily run built and installed binaries:
# Include every ./bin directory from GOPATHs into PATH
export PATH="$PATH:${GOPATH//://bin:}/bin"
$GOPATH contains three high-level directories —
$GOPATH/src— Your all code resides here$GOPATH/pkg— Contains package archives (.a) used by Go internally to run itself$GOPATH/bin— Contains executable binaries like godep, golint
With the latest release of Go 1.11, Go Modules are introduced which let you create your project outside the $GOPATH and improves package management a lot.
https://github.com/RHCloudServices/golang-intro