Updating golang on Ubuntu

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

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.


I have found an alternative(/personal) repo with latest versions, which is still alive, then got the go-1.8 and linked it from the path in the OP's question. Here be bash it in:

sudo add-apt-repository ppa:gophers/archive
sudo apt-get update

sudo apt-get install golang-1.8

sudo ln /usr/lib/go-1.8/bin/go /usr/bin/go1.8

Now I can just say go1.8 instead of go and thus go with the latest&greatest.

The repo offers many other versions so you'd just change the version number to ex. 1.4 in the script/commands above.

Tags:

Updates

Golang