Installing the Go programming language in Ubuntu

Go is a programming language and is available in most Linux distributions. Sometime Go is preinstalled, other times we need to install ourselves, or we need to update the existing version to a newer version.

Go in Ubuntu 16.04

Ubuntu 16.04 comes with Go version 1.6. The package name is golang (same as their website domain, GoLang.org). Let’s install it and then view the details of the package.

$ sudo apt update
...
$ sudo apt install golang
...
$ apt policy golang
golang:
 Installed: 2:1.6-1ubuntu4
 Candidate: 2:1.6-1ubuntu4
 Version table:
*** 2:1.6-1ubuntu4 500
    500 http://archive.ubuntu.com/ubuntu xenial/main amd64 Packages
    500 http://archive.ubuntu.com/ubuntu xenial/main i386 Packages
    100 /var/lib/dpkg/status

Newer Go in Ubuntu 16.04

In same cases, Go 1.6 is dated, and we may want to install a newer version. There are three main options.

Installing newer Go from backports in Ubuntu 16.04

To install a newer Go from the backports repository in Ubuntu 16.04,

  1. Remove any older version of Go
    $ sudo apt remove golang
  2. Start the Software & Updates program.
  3. In the Updates tab, tick on Unsupported updates (xenial-backports). Then, when prompted, click to Reload the index.
  4. In a terminal window, run the following to install Go 1.9. Currently, the latest version of Go is 1.9.
    $ sudo apt install golang-1.9

    $ /usr/lib/go-1.9/bin/go version
    go version go1.9.2 linux/amd64
  5. Add the directory /usr/lib/go-1.9/bin to your $PATH
    $ echo ‘PATH=”/usr/lib/go-1.9/bin:$PATH”‘ >> ~/.profile
    $ source ~/.profile
    $ go version
    go version go1.9.2 linux/amd64
  6. That’s it!

Installing newer Go as a snap package

Go is also available as a snap package.

If you have not installed yet snap support in your Linux distribution, see https://docs.snapcraft.io/core/install to do so. Note that the Go snap requires classic mode, therefore if a distribution has a note about no-classic, you cannot install snap support.

Let’s see what is available as a snap package for Go.

$ snap info go
name: go
summary: Go programming language compiler, linker, stdlib
publisher: mwhudson
contact: michael.hudson@ubuntu.com
description: |
 This snap provides an assembler, compiler, linker, and compiled libraries for
 the Go programming language.
snap-id: Md1HBASHzP4i0bniScAjXGnOII9cEK6e
channels: 
 stable: 1.9.3 (1333) 55MB classic
 candidate: ↑ 
 beta: 1.10beta1 (1167) 64MB classic
 edge: devel-851e98f (1356) 133MB classic
 1.10/stable: – 
 1.10/candidate: 1.10rc1 (1340) 64MB classic
 1.10/beta: 1.10beta1 (1167) 64MB classic
 1.10/edge: ↑ 
 1.6/stable: 1.6.4 (122) 49MB classic
 1.6/candidate: ↑ 
 1.6/beta: ↑ 
 1.6/edge: ↑ 
 1.7/stable: 1.7.6 (324) 48MB classic
 1.7/candidate: ↑ 
 1.7/beta: ↑ 
 1.7/edge: ↑ 
 1.8/stable: 1.8.5 (1018) 51MB classic
 1.8/candidate: ↑ 
 1.8/beta: ↑ 
 1.8/edge: ↑ 
 1.9/stable: 1.9.3 (1333) 55MB classic
 1.9/candidate: ↑ 
 1.9/beta: ↑ 
 1.9/edge: ↑

The stable version is currently 1.9.3. We also have the option of older versions, starting from Go 1.6. After Go 1.9, the next version will be 1.10. That version is not available as stable yet but only as beta. This is because Go 1.10 has not been officially released yet by their developers.

Let’s install Go as a snap package.

$ sudo snap install go --classic 
go 1.9.3 from 'mwhudson' installed

$ which go
/snap/bin/go

$ go version
go version go1.9.3 linux/amd64

Installing a newer go with the Ubuntu Make snap

Ubuntu Make can install all sort of development packages. It used to be particularly useful before snaps where made generally available. Now, it has quite diverse support so it is still useful for the easy installation of certain development packages. Probably not so important for Go.

$ sudo snap install ubuntu-make --classic
ubuntu-make master from 'didrocks' installed

$ ubuntu-make.umake go
Choose installation path: /home/ubuntu/.local/share/umake/go/go-lang
Downloading and installing requirements |
100% |############################################################################|
Installing Go Lang
|#################################################################################|
You may need to log back in for your Go Lang installation to work properly
Installation done
$ tail -3 ~/.profile
# Ubuntu make installation of Go Lang
PATH=/home/ubuntu/.local/share/umake/go/go-lang/bin:$PATH
export GOROOT=/home/ubuntu/.local/share/umake/go/go-lang

$ source ~/.profile 
$ which go
/home/ubuntu/.local/share/umake/go/go-lang/bin/go
$ go version
go version go1.9.3 linux/amd64
$

To remove Go that was installed with the Ubuntu Make snap, do the following

$ ubuntu-make.umake -r go
Removing Go Lang
Suppression done

This command also cleans up ~/.profile.

Installing a newer go with Ubuntu Make from PPA

Ubuntu Make is a script that helps to install all sorts of development packages, including Go. There is a snap package of Ubuntu Make, but there is also a PPA repository. We use now the PPA repository (earlier we used the snap package).

We add the PPA and update the package index.

$ sudo add-apt-repository ppa:lyzardking/ubuntu-make
$ sudo apt-get update

We install the ubuntu-make package.

$ sudo apt-get install ubuntu-make

We use umake to install Go.

$ umake go
Choose installation path: /home/ubuntu/.local/share/umake/go/go-lang
Downloading and installing requirements |
100% |##########################################################################|
Installing Go Lang
|###############################################################################|
You may need to log back in for your Go Lang installation to work properly
Installation done
$

Ubuntu Make automatically added the correct lines to edit the $PATH. We then verify the installation of Go.

$ tail -3 .profile 
PATH=/home/ubuntu/.local/share/umake/go/go-lang/bin:$PATH
export GOROOT=/home/ubuntu/.local/share/umake/go/go-lang

$ which go
/home/ubuntu/.local/share/umake/go/go-lang/bin/go
$ go version
go version go1.9.3 linux/amd64
$

Conclusion

These are the main ways to install Go in Ubuntu. It is recommended to install the latest stable version, which at the time of writing this, is Go 1.9.3.

There is also a short guide at the official Go Wiki on installing Go in Ubuntu.

Permanent link to this article: https://blog.simos.info/installing-the-go-programming-language-in-ubuntu/

1 comment

1 ping

  1. Here’s another great place to learn some more about Golang: https://www.activestate.com/activego

  1. […] Installing the Go programming language in Ubuntu […]

Leave a Reply to AliCancel reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.