How to install Go language on Linux

Go (also called "golang") is an open-source programming language initially developed by Google. It was born with several design principles in mind: simplicity, safety, and speed. The Go language distribution comes with various tools for debugging, testing, profiling and code-vetting. Nowadays the Go language and its tool chain are available in the base repositories of most Linux distributions, allowing you to install them with a default package manager. However, note that your distro's repository may provide a little bit outdated version. If you need the latest version of Go, install it from the official website. This tutorial describes both ways to install Go and its tool chain.

Install Go Language on Ubuntu, Debian or Linux Mint

The following apt-get command will install Go language and its development tools on Debian-based distributions.

$ sudo apt-get install golang

Check the version of Go language to verify installation.

$ go version
go version go1.2.1 linux/amd64

Since Go code must be kept inside a workspace, create a workspace directory in your home directory (e.g., ~/go). This is where the Go tool builds source packages and installs the binaries.

$ mkdir ~/go

Then set up Go related environment variables system-wide as follows.

$ sudo vi /etc/profile.d/goenv.sh
export GOROOT=/usr/lib/go
export GOPATH=$HOME/go
export PATH=$PATH:$GOROOT/bin:$GOPATH/bin
$ source /etc/profile.d/goenv.sh

Depending on your need, you may want to install additional Go tools using apt-get.

$ sudo apt-cache search golang

Install Go Language on Fedora, CentOS/RHEL

The following yum command will install Go language and its development tools on Red Hat based distributions.

$ sudo yum install golang

Check the version of Go language to verify installation.

$ go version
go version go1.3.3 linux/amd64

Next, create a workspace directory in your home directory (e.g., ~/go), which is where the Go tool builds source packages and installs the binaries. Then define Go related environment variables.

$ mkdir ~/go
$ sudo vi /etc/profile.d/goenv.sh
export GOROOT=/usr/lib/golang
export GOPATH=$HOME/go
export PATH=$PATH:$GOROOT/bin:$GOPATH/bin
$ source /etc/profile.d/goenv.sh

Depending on your need, you can install additional Go tools using yum.

$ yum search golang

Install Go Language from the Official Website

Sometimes the version of Go language that comes with your Linux distribution may not be up-to-date. In that case, you can install the latest Go language from its official website. Here is how you can do it.

Go to the official source of Go language, and download pre-built binaries.

For 64-bit Linux:

$ wget https://storage.googleapis.com/golang/go1.4.1.linux-amd64.tar.gz

For 32-bit Linux:

$ wget https://storage.googleapis.com/golang/go1.4.1.linux-386.tar.gz

Install the binaries under /usr/local.

$ sudo tar -xzf go1.4.1.linux-xxx.tar.gz -C /usr/local

Create a workspace directory in your home directory (e.g., ~/go), and define Go related environment variables system-wide as follows.

$ mkdir ~/go
$ sudo vi /etc/profile.d/goenv.sh
export GOROOT=/usr/local/go
export GOPATH=$HOME/go
export PATH=$PATH:$GOROOT/bin:$GOPATH/bin
$ source /etc/profile.d/goenv.sh

Check the version of Go language.

$ go version
go version go1.4.1 linux/amd64
Download this article as ad-free PDF (made possible by your kind donation): 
Download PDF

Subscribe to Ask Xmodulo

Do you want to receive Linux related questions & answers published at Ask Xmodulo? Enter your email address below, and we will deliver our Linux Q&A straight to your email box, for free. Delivery powered by Google Feedburner.


Support Xmodulo

Did you find this tutorial helpful? Then please be generous and support Xmodulo!

Leave a comment

Your email address will not be published. Required fields are marked *