How to Install Go on Ubuntu Linux and CentOS

GO is a general purpose system programming language which means that you can build wide variety of application using it. It is purely an open source language developed by Google. It has cross platform, which supports all major operating systems.

Go source code is compared to a binary executable or library, this results in a very high performance when running Go application. Compilation speed for the Go applications are really fast. In a nutshell, Go is an elegant language with a clean and concise specifications that are readable and comprehensive. One of the major strengths of Golang is its concurrency, which means multiple process of the Go applications can run at same time.

In this article, I'll explain how to install Go language on our latest Linux distributions of Ubuntu and CentOS.

Install Go language on Ubuntu (16.04)

Go language and its tool kits are available in  our base repositories in all the major operating systems. We can install Go language in Ubuntu by just running this command.

[email protected]:~# apt-get install golang

[email protected]:~# go version
go version go1.6.1 linux/amd64

Now, we need to place the Go codes inside a work directory where, we can build the Go tools and install its binaries. I created a directory for Go codes in /home folder.

[email protected]:~# mkdir /home/go

Create a file "/etc/profile.d/" for setting up Go environment variable server-wide as below:

[email protected]:~# cat /etc/profile.d/
export GOROOT=/usr/lib/go
export GOPATH=$HOME/go
export PATH=$PATH:$GOROOT/bin:$GOPATH/bin

[email protected]:~# source /etc/profile.d/

Install Go language on CentOS 7

As I explained before, it is quite easy to install Go Language in Redhat Based distributions too. It is available in their base repository packages. We can install it by just running this command below:

[[email protected] ~]# yum install golang

it will install all required packages for this language.


You can confirm with the Go version installed.

[[email protected] ~]# go version
go version go1.4.2 linux/amd64

We can manage the Go source codes using the "Go" tool. There are many commands which can be used with Go tool. Here are the list of them.

go tools

We can get more information regarding each command usage by executing "go command help" like go build help or go install help.

You can create a work folder in this installation too, which will help you to build and install its binaries. Furthermore, create the environment variables server-wide..

[[email protected] ~]# mkdir ~go

[[email protected] ~]# source /etc/profile.d/

[[email protected] ~]# cat /etc/profile.d/
export GOROOT=/usr/lib/go
export GOPATH=$HOME/go
export PATH=$PATH:$GOROOT/bin:$GOPATH/bin

Install latest version 1.6 from Source

If you notice, in the above installations, you can see that the versions of Go language packages installed is different in two distributions. This means that it's not mandatory to have the latest versions available on our base repository packages. So whenever we need to install the latest package, we can download it direct from the source and install. Let's see how to do that.

Depending on our server architecture, we can download the required package and extract to install.

[[email protected] src]# wget

2016-07-01 07:50:26 (93.6 MB/s) - ‘go1.6.2.linux-amd64.tar.gz’ saved [84840658/84840658] [[email protected]]# tar -xzvf go1.6.2.linux-amd64.tar.gz -C /usr/local/

I've downloaded the package for a 64 bit architecture. You can create a work folder set environment variables server-wide as before.

[email protected]~]# mkdir ~go

[[email protected] ~]# cat /etc/profile.d/
export GOROOT=/usr/local/go
export GOPATH=$HOME/go
export PATH=$PATH:$GOROOT/bin:$GOPATH/bin

[[email protected] ~]# source /etc/profile.d/

[[email protected] bin]# go version
go version go1.6.2 linux/amd64

The only difference in creating environment variable is that, here the Go libraries reside inside our /usr/local folder comparing the above cases.

A Simple program in Go

Now we can test our installation by creating a test program. Our first sample program will print the  “hello world” message.  Create a file to print "helloworld.go".


Now we need to run this program using go command.

 [[email protected] ~]# go run helloworld.go
hello world

At times, we’ll need to build our programs into binaries. We can use build command for that.

[[email protected] ~]# go build helloworld.go
[[email protected] ~]# ls
helloworld helloworld.go

We can then execute the built binary directly like this.

[[email protected] ~]# ./helloworld
hello world

If this works, means you've built your Go successfully :)

You can get more examples of this program to start learning. I hope you enjoyed reading this article. I would recommend your valuable suggestions and comments on this.Have a Good day!

Saheetha Shameer 3:00 am

About Saheetha Shameer

I’m working as a Senior System Administrator. I’m a quick learner and have a slight inclination towards following the current and emerging trends in the industry. My hobbies include hearing music, playing strategy computer games, reading and gardening. I also have a high passion for experimenting with various culinary delights :-)

Author Archive Page

Have anything to say?

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

All comments are subject to moderation.