This has been the most annoying thing to deal with. In hopes of saving your time.
IF go was installed as root user. The root user of your system’s bash_profile text file ~/.bash_profile needs to have $GOROOT assigned to the go install directory and $GOPATH needs to be assigned to go /src directory.
...$# sudo su ...$# vi ~/.bash_profile ***Story continues in vi editor*** GOROOT=$GOROOT:/usr/local/go GOPATH=$GOPATH:/usr/local/go/src ... [your regular PATH stuff here] ...
be sure the path to go binary is in your path on .bash_profile
This PATH can be as long a string it needs to be..to add new items just separate by colon :
exit vi editor and saving bash profile (:wq stands for write and quit)
[esc] [shift] + [:] :wq
You have to log out of terminal and log back in for profile to initiate again..or you can just kick start it by using export.
...$# export GOPATH=/usr/local/go/src
You can verify go env:
...$# go env
GOBIN="" GOCHAR="6" GOEXE="" GOHOSTARCH="amd64" GOHOSTOS="linux" GOOS="linux" GOPATH="/usr/local/go/src" GORACE="" GOROOT="/usr/local/go"
Now you can sudo and go will be able to download and create directories inside go/src and you can get down to what you were trying to get done.
# sudo go get github.com/..
Now you will run into another problem..you might not have git installed..that’s another adventure..: