Golang Code

How to Install Go in Ubuntu 16.04/18.04

· 144 words · 1 minute read #16.04 #18.04 #bash #install #local #path #profile #ubuntu #vim #wget

Ubuntu does come with a version of go (installable through apt install go) but it won’t be as up-to-date as downloading it directly. And I know many gophers like using the latest version.

To being we’ll start by downloading the latest version and once downloaded we extract it into a folder we can work with.

wget https://dl.google.com/go/go1.10.2.linux-amd64.tar.gz
sudo tar -C /usr/local -xvf go1.10.2.linux-amd64.tar.gz

We then need to add some bash variables so Go knows where our work/code directory is located. GOPATH should point to the folder where you’ll be working in. This folder once setup should have your src, bin and pkg folders.

vim ~/.profile

Add this to the bottom:

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

Press :wq to exit and run this to load your changes:

source ~/.profile

As the final test, if we run this:

go version

We should see go version go1.10.2 linux/amd64

Image of Author Edd Turtle

Author: Edd Turtle

Edd is the Lead Developer at Hoowla, a prop-tech startup, where he spends much of his time working on production-ready Go and PHP code.

See something which isn't right? You can contribute to this page on GitHub or just let us know in the comments below. Thanks for reading!