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

Share:
22,011
Mnemosyne
Author by

Mnemosyne

Just a lurker. Don't mind me.

Updated on July 09, 2022

Comments

  • Mnemosyne
    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
      Allan over 6 years
    • Tobias Gassmann
      Tobias Gassmann over 6 years
      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.
    • Mnemosyne
      Mnemosyne over 6 years
      I know how to make variables permanent and setting the path. The problem is Go variables do not seem to persist whatever I do.
    • philoj
      philoj over 3 years
      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
    • Tom J
      Tom J over 2 years
      If you think this is a good question you should vote it up.
  • Mnemosyne
    Mnemosyne over 6 years
    I did that but the change did not persist for new terminals.
  • Pastello
    Pastello about 5 years
    Try adding those two lines also at the bottom of ~/.bashrc