How to set Go environment variables globally
22,011
As explained here you just need to include exports
export GOROOT=/usr/lib/go-1.9/
export GOPATH=/my/workspace/go
at the bottom of the file ~/.profile in your home directory
Comments
-
Mnemosyne almost 2 years
when I declare my Go environment (namely GOPATH and GOROOT using simple export):
export GOROOT=/usr/lib/go-1.9/ export GOPATH=/my/workspace/go
The current terminal recognizes the variables normally, but if I open another terminal window, these variables are not set and they need to be reconfigured from scratch.
Is there a go-specific way to set default values for go environment variables other than common ways like editing the .bashrc file?
-
Allan over 6 yearsPossible duplicate of How to permanently export a variable in Linux?
-
Tobias Gassmann over 6 yearswhy was this quesiton put on hold? It is a valid question on how to make environment variables permanant. This is not a question limited to Super User since it is a daily task for developers also.
-
Mnemosyne over 6 yearsI know how to make variables permanent and setting the path. The problem is Go variables do not seem to persist whatever I do.
-
philoj over 3 yearsActually, you can run
$ go env -w GOROOT=/usr/lib/go-1.9/
theses days to make the value permanent. I think this question would be useful since it is the best way to set the go environment -
Tom J over 2 yearsIf you think this is a good question you should vote it up.
-
-
Mnemosyne over 6 yearsI did that but the change did not persist for new terminals.
-
Pastello about 5 yearsTry adding those two lines also at the bottom of ~/.bashrc