How to Install Go 1.7 on Ubuntu 16.04 / 14.04 / CentOS 7 / Fedora 24

Install Go 1.7 on Ubuntu 16.04
Install Go 1.7 on Ubuntu 16.04

Go Lang is an open source programming language developed by a team of Google engineers in 2007. Go language was designed to resolve the common criticisms of other languages while maintaining their positive characteristics and most widely used for writing servers these days.

Most notable projects using Go language are,

  1. Docker, a set of tools for deploying containers
  2. Juju, a service orchestration tool by canonical
  3. Dropbox moved the critical components to Go lang from python
  4. snappy, a package manager


System Requirements:

Go binary packages are available for below supported operating systems. Please ensure your system meets these requirements before installing Go language.

Operating systemArchitecturesNotes
FreeBSD 8-STABLE or laterx86_64Debian GNU/kFreeBSD not supported
Linux 2.6.23 or later with glibcx86_64, 386, armCentOS/RHEL 5 not supported
Mac OS X 10.7 or laterx86_64use the clang or gcc that comes with Xcode for cgo support
Windows XP or laterx86_64, 386use MinGW gcc. No need for Cygwin or msys.

This guide will help you to do the installation of Go 1.7 Lang on Ubuntu 16.04, Ubuntu 14.04, CentOS 7, RHEL 7, and Fedora 24.

Download and Install Go Language:

Before installing Go language, update your system with the latest security patches to ensure the system is not vulnerable.

Switch to the root user.

$ su -

Update your system using the following command.

### Ubuntu 16.04 / 14.04 ###

# apt-get update
# apt-get -y upgrade

### CentOS / RHEL / Fedora ###

# yum -y update

Download the Go language binary package using the following command. Alternatively, you can visit Go Language download page to download the latest version of Go.

# wget

Extract the archive and move it to /usr/local. You can also place the Go lang binary to your custom location instead of /usr/local.

# tar -zxvf  go1.7.1.linux-amd64.tar.gz -C /usr/local/

Setup Go Environment variables:

Now you would need to setup two important variables for Go, GOROOT (PATH) and GOPATH. Add /usr/local/go/bin to your path variable. You can add this by running below command (temporary) or place the following command in /etc/profile or $HOME/.profile file for persistent across sessions.

export PATH=$PATH:/usr/local/go/bin

If you have installed Go on custom location replace /usr/local/go/bin/ with /path/to/bin/ directory.

GOPATH is a Go environment variable for your project workspace. Let’s create a workspace directory called “work” in your home directory.

mkdir $HOME/work

Set GOPATH variable. You can add this by running below command (temporary) or place the following command in /etc/profile or $HOME/.profile file for persistent across sessions.

export GOPATH=$HOME/work

Verify Go Installation:

Run the below command to see the version of Go language.

# go version
go version go1.7.1 linux/amd64

Check the Go environment variables we set in previous sections.

# go env

GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0"

Create your first project:

Assuming that you have workspace called “work” located in $HOME directory. I am a root user, in my case “/root/work” is my workspace. Go to your workspace.

# cd $GOPATH
# cd $HOME/work

Create a directory “src/hello” under your workspace.

# mkdir -p src/hello

Let’s create a simple program (hello) to test the Go installation.

# vi src/hello/hello.go

Place the following content in the hello.go file.

package main

import "fmt"

func main() {
    fmt.Printf("Welcome To ITzGeek\n")

Now, compile it with go command.

# go install hello

go command will put an executable command (hello) inside the bin directory of your workspace. Execute the executable using the following command.

# $GOPATH/bin/hello

You should get the following greeting text.

Welcome To ITzGeek

That’s all. You have successfully installed Go on Ubuntu 16.04.


Share This Post