How to update your Go version

Brief commands to update you go version in Ubuntu

This is a simple tutorial on how update you Go version in Ubuntu.

First, download the desired version from the official Go website.

Then, go into your Downloads folder and unpack the downloaded file

sudo tar -xvf {{GO_VERSION}}.linux-amd64.tar.gz

This will generate a go directory

Erase your current go directory and replace with your new one

sudo rm -rf /user/local/go

sudo mv go /usr/local

If necessary, update you ENV variables. They are either in .zshrc, .profile, .bashrc, better check them out.

export GOROOT=/usr/local/go

export GOPATH=$HOME/go

To be able to run the go command without need to reference the binary application, make sure to install a system wide installation of $PATH variable to reference the right place where binaries are located. Navigate into /etc/profile and type:

export PATH=$PATH:/usr/local/go/bin

Or just place the line above into ~/.profile file for a user based configuration.

This ensure we can run myapp instead of $GOPATH/bin/myapp

More information about GOPATH in this amazing digital ocean article

That’s it. To ensure everything is working properly, refresh the terminal and type:

go version

You can also try to build some .go file you have, like go build ./hello.go.

Hope it helps!