How do I SET the GOPATH environment variable on Ubuntu? What file must I edit?

New Way:

Check out this answer.

Note: Not for trying out a go application / binaries on your host machine using go install [repo url], in such cases you still have to use the old way.

Old Way:

Just add the following lines to ~/.bashrc and this will persist. However, you can use other paths you like as GOPATH instead of $HOME/go in my sample.

export GOPATH=$HOME/go
export PATH=$PATH:$GOROOT/bin:$GOPATH/bin

Leave a Comment