My answer is in reference to the setting-up of go-lang
on Ubuntu linux/amd64
.I have faced the same trouble of setting the path of environment variables (GOPATH
and GOBIN
), losing it on terminal exit and rebuilding it using the source <file_name>
every time.The mistake was to put the path (GOPATH
and GOBIN
) in ~/.bash_profile
folder. After wasting a few good hours, I found that the solution was to put GOPATH
and GOBIN
in ~/.bash_rc
file in the manner:
export GOPATH=$HOME/go
export GOBIN=$GOPATH/bin
export PATH=$PATH:$GOPATH:$GOBIN
and doing so, the go installation worked fine and there were no path losses.
EDIT 1:
The reason with which this issue can be related is that settings for non-login shells like your ubuntu terminal or gnome-terminal where we run the go code are taken from ~./bash_rc
file and the settings for login shells are taken from ~/.bash_profile
file, and from ~/.profile
file if ~/.bash_profile
file is unreachable.