In Go's wiki page on Github, it is told to be set in ~/.bash_profile:
https://github.com/golang/go/wiki/Setting-GOPATH
In this StackOverflow question most of the top voted answers suggested to be set in the ~/.bashrc file:
how do I SET the GOPATH environment variable on Ubuntu? What file must I edit?
I have read that ~/.profile is perhaps the best way to set environment variables. Is there a reason that ~/.profile is not used to set $GOPATH or is it just a matter of preference?
If you have a .bash_profile
file already, you can use it, else use .profile
. You could also source .profile
from .bash_profile
and add anything you need to .profile
instead; see this answer for more info.
.bashrc
?If you add environment variables to .bashrc
, you can experience things like duplicate PATH
entries, but it also means those vars are only available in a process launched from a shell. For GOPATH
, that usually isn't a problem, but it is PATH
-like, so you should stick with the shell profile to avoid any potential issues.