5

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?

Thomas BDX
  • 2,632
  • 2
  • 27
  • 31
Mnemosyne
  • 1,162
  • 4
  • 13
  • 45
  • 2
    Possible duplicate of [How to permanently export a variable in Linux?](https://stackoverflow.com/questions/13046624/how-to-permanently-export-a-variable-in-linux) – Allan Jan 21 '18 at 05:13
  • 1
    why 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. – Tobias Gassmann Jan 23 '18 at 09:59
  • I know how to make variables permanent and setting the path. The problem is Go variables do not seem to persist whatever I do. – Mnemosyne Jan 24 '18 at 22:32
  • 5
    Actually, 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 – philoj Nov 18 '20 at 08:32
  • If you think this is a good question you should vote it up. – Tom J Nov 27 '21 at 04:48

1 Answers1

5

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

Pastello
  • 119
  • 3
  • 9