Setting up Go on Ubuntu

This is a quick guide to getting started with Golang on Ubuntu 20.04 with the bash shell.

Download

From the Golang website, download the latest version of Go for Linux to your Downloads folder, as of this writing it is:

go1.16.3.linux-amd64.tar.gz

Install

Open a bash terminal (CTRL+ALT+T) and make sure you are in your home folder:

cd ~/

If you already have a version of Go installed, remove it:

sudo rm -rf /usr/local/go

Uncompress your downloaded file to the /usr/local folder:

sudo tar -C /usr/local/ -xzf Downloads/go1.16.3.linux-amd64.tar.gz

Configure

Open .bashrc with your favourite editor, I am using vim here:

vim ~/.bashrc

And add the following to the end of the file:

export GOPATH=$HOME/go

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

Save and close the modified file, and then create the go folder to store packages:

mkdir ~/go

Close the terminal by entering exit, or clicking the close window button.

Test

Reopen the terminal, and type the following to confirm go is correctly installed:

go version

You should see displayed the version you just installed, in my case:

go version go1.16.3 linux/amd64

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s