Updating golang on Ubuntu

Solution 1:

ppa:evarlast/golang1.4 is not working for me. The manual way of installing Go is given below.

Step 1: Remove the existing golang

sudo apt-get purge golang*

Step 2: Download the latest version from the official site. Click Here

Step 3: Extract it in /usr/local using the following command. I am using Go 1.11.4 here. You may need to replace the filename with the actual filename based on the version you have downloaded.

tar -C /usr/local -xzf go1.11.4.linux-amd64.tar.gz

Step 4: Create .go directory in home. (It is easy to install the necessary packages without admin privilege)

mkdir ~/.go

Step 5: Set up the following environment variables

GOROOT=/usr/local/go
GOPATH=~/.go
PATH=$PATH:$GOROOT/bin:$GOPATH/bin

Check this AskUbuntu answer for how to set environment variables permanently.

Step 6: Update the go command

sudo update-alternatives --install "/usr/bin/go" "go" "/usr/local/go/bin/go" 0
sudo update-alternatives --set go /usr/local/go/bin/go

Step 7: Test the golang version

go version

For more detailed installation instruction: Install the latest Golang on Linux

Solution 2:

First remove your current golang installation with this command, you don't need to manually remove files installed by apt-get,

sudo apt-get purge golang

For an easy install of golang 1.4 you can use this PPA

sudo add-apt-repository ppa:evarlast/golang1.4
sudo apt-get update

Now you can use

sudo apt-get install golang

This will install version 1.4, here is a link to the PPA.