Install Go(Golang) on Ubuntu

There are many ways to configure the Go development environment on your computer, you can choose any one you like. The three most common ways are as follows.


Official installation packages
The Go team provides convenient installation packages in Windows, Linux, Mac
and other operating systems. The easiest way to get started.

Install from source code
Popular with developers who are familiar with Unix-like systems.

Use third-party tools
There are many third-party tools and package managers for installing Go, like apt-
get in Ubuntu and homebrew for Mac.

In case you want to install more than one version of Go in one computer, you should take a look at the tool called GVM. It is the best tool I’ve seen so far for achieving this job,  otherwise you have to know how to deal with this problem by yourself.


Using GVM

1. Make sure to install pre-requisite libraries first

sudo apt-get update
sudo apt-get install curl git mercurial make binutils bison gcc

2. Install GVM

bash < <(curl -s

3. Install Go

gvm install go1.2
gvm use go1.1.2 [--default]
gvm list

Install Go Binary

1.  Install required libraries

sudo apt-get install python-software-properties  # 12.04
sudo add-apt-repository ppa:duh/golang
sudo apt-get update

2. Install Go

sudo apt-get install golang

3. export the settings you’re gonna need to bash_rc or equivalent:

export GOROOT=/usr/lib/go
export GOBIN=/usr/bin/g

From Source

1. Dependencies

sudo apt-get update
sudo apt-get install gcc make mercurial git libc6-de

2. Building from source

hg clone -u release
$ cd go/src
$ ./all.bas

3. The GOPATH environment variable

Go commands all rely on one important environment variable which is called $GOPATH. Notice that this is not the $GOROOT where Go is installed. This variable points to the workspace of Go in your computer. (I use this path in my computer, if you don’t have the same directory structure, please replace by yourself.)

export GOPATH=$HOME/gocode
export PATH=$PATH:$GOPATH/bin

Note:- If your Go version is greater than 1.0, you don’t have to set $GOBIN, and it will automatically be related to your $GOROOT/bin, which we will talk about in the next section

You can install any of the above three way. I mostly prefer using GVM. I hope it will help you.!

6 thoughts on “Install Go(Golang) on Ubuntu

  1. Hey thanks so much for the tutorial! Just wanted to point out a typo in the “from source” way – it’s ./all.bash, not ./all.bas. Thanks again!

Leave a Reply

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

You are commenting using your 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