Objective

Go is an open source programming language developed by Google. The objective is to install latest Go language pre-compiled binaries on Ubuntu 16.04 Linux.

Requirements

Privileged access to your Ubuntu System as root or via sudo command is required.

Difficulty

EASY

Conventions

  • # - requires given linux commands to be executed with root privileges either directly as a root user or by use of sudo command
  • $ - requires given linux commands to be executed as a regular non-privileged user

Instructions

Download Go language binaries

First, we need to download Go language binaries. Visit https://golang.org/dl/ page and either download your relevant Golang Linux libraries directly using your browser or simply use wget command as shown below:
$ wget -q https://storage.googleapis.com/golang/go1.7.4.linux-amd64.tar.gz
Once downloaded, you should be able to see the Go tarball with ls command:
$ ls go*
go1.7.4.linux-amd64.tar.gz

Install Go binaries

The installation of Go binaries simply involves a previously downloaded tarball decompression into a desired directory. The below command will extract the content of go1.7.4.linux-amd64.tar.gz tarball into /usr/local/bin/go directory.
$ sudo tar -C /usr/local/bin -xzf go1.7.4.linux-amd64.tar.gz
Check the content of /usr/local/bin directory:
$ ls /usr/local/bin/
go

Setup Go Environment

All Go binaries are now ready, what remains, is Go environment setup. To do so, open your favorite text editor and append the following lines into your ~/.bashrc file:
# golang local root installation directory
export GOROOT=/usr/local/bin/go
# golang binary-release PATH.
export PATH=${PATH}:${GOROOT}/bin

# golang binaries location
export GOPATH=$HOME/go
# golang compiled binaries PATH.
export PATH=${PATH}:${GOPATH}/bin
Now we need to source the above edited ~/.bashrc file which makes all new Go environment variables available. To do so, either re-login from your current shell session or execute:
$ . .bashrc

Testing Go Language Installation

All should now be ready. First, check go version:
$ go version
go version go1.7.4 linux/amd64
Execute a sample hello world example:
$ sudo apt-get install git
$ go get github.com/golang/example/hello
$ hello 
Hello, Go examples!
Go Language hello world example ubuntu
ARE YOU LOOKING FOR A LINUX JOB?
Submit your RESUME, create a JOB ALERT or subscribe to RSS feed on LinuxCareers.com.
LINUX CAREER NEWSLETTER
Subscribe to NEWSLETTER and receive latest news, jobs, career advice and tutorials.
DO YOU NEED ADDITIONAL HELP?
Get extra help by visiting our LINUX FORUM or simply use comments below.

You may also be interested in: