Best Way to Install Go 1.7 on Ubuntu


Go is a free and open source programming language created by Google in 2007. It supplies convenient to construct simple, nontoxic, and effective programs. This language is designed for writing on servers. This article explains about ‘How to install Go 1.7 on Ubuntu’

Installing Go Programming language

To download Go language binary archive file, use the following command –

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

The sample output should be like this –

--2016-12-29 10:49:44-- https://storage.googleapis.com/golang/go1.7.1.linux-amd64.tar.gz
Resolving storage.googleapis.com (storage.googleapis.com)... 216.58.197.48, 2404:6800:4007:807::2010
Connecting to storage.googleapis.com (storage.googleapis.com)|216.58.197.48|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 81618401 (78M) [application/x-gzip]
Saving to: ‘go1.7.1.linux-amd64.tar.gz’

go1.7.1.linux-amd64 100%[===================>] 77.84M 5.98MB/s in 16s

2016-12-29 10:50:01 (4.78 MB/s) - ‘go1.7.1.linux-amd64.tar.gz’ saved [81618401/81618401]

To extract the downloaded archive file and move to the desired location on system, use the following command –

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

The sample output should be like this –

go/
go/AUTHORS
go/CONTRIBUTING.md
go/CONTRIBUTORS
go/LICENSE
go/PATENTS
go/README.md
go/VERSION
go/api/
go/api/README
go/api/except.txt
go/api/go1.1.txt
go/api/go1.2.txt
go/api/go1.3.txt
go/api/go1.4.txt
go/api/go1.5.txt
go/api/go1.6.txt
go/api/go1.7.txt
go/api/go1.txt
go/api/next.txt
go/bin/
go/bin/go
go/bin/godoc
go/bin/gofmt
go/blog/
go/blog/content/
go/blog/content/4years-gopher.png
go/blog/content/4years-graph.png
go/blog/content/4years.article
go/blog/content/5years/
go/blog/content/5years/conferences.jpg
go/blog/content/5years/gophers5th.jpg
go/blog/content/5years.article
go/blog/content/6years-gopher.png
go/blog/content/6years.article
go/blog/content/a-conversation-with-the-go-team.article
go/blog/content/advanced-go-concurrency-patterns.article
go/blog/content/appengine-dec2013.article
.......................................................................

Setting Go Environment

There are two ways to setting up Go Environment. The following are the methods as shown below –

  • Current session
  • Permanent set up

Current session

Current session set up should be applicable for the current working session only. To set up Go environment, use the following steps-

To set GOROOT environment variable, use the following command –

$ export GOROOT=/usr/local/go

To set up GOPATH for work location, use the following command –

$ export GOPATH=$HOME/tutorialspoint/sample

To set the PATH variable to access go binary system, use the following command –

$ export PATH=$GOPATH/bin:$GOROOT/bin:$PATH

Permanent Setup

Permanent set up should be applicable for all the time. To set up Go environment, use the following steps –

To open .profile file, use the following command –

$ sudo nano ~/.profile

The sample output should be like this –

# ~/.profile: executed by the command interpreter for login shells.
# This file is not read by bash(1), if ~/.bash_profile or ~/.bash_login
# exists.
# see /usr/share/doc/bash/examples/startup-files for examples.
# the files are located in the bash-doc package.

# the default umask is set in /etc/profile; for setting the umask
# for ssh logins, install and configure the libpam-umask package.
#umask 022
...............................................................

Now add the following lines at end of the file as shown below –

export GOROOT=/usr/local/go
export GOPATH=$HOME/tutorialspoint/sample
export PATH=$GOPATH/bin:$GOROOT/bin:$PATH

Now save and close the file.To refresh your profile, use the following command –

$ source ~/.profile

To verify the go version, use the following command –

$ go version

The sample output should be like this –

go version go1.7.1 linux/amd64

To verify all configured environment variables, use the following command –

$ go env

The sample output should be like this –

GOARCH="amd64"
GOBIN=""
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"
GOPATH="/home/tutorialspoint/tutorialspoint/sample"
GORACE=""
GOROOT="/usr/local/go"
GOTOOLDIR="/usr/local/go/pkg/tool/linux_amd64"
CC="gcc"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build771783301=/tmp/go-build -gno-record-gcc-switches"
CXX="g++"
CGO_ENABLED="1"

After this article, you will be able to understand – How to install Go 1.7 on Ubuntu 16.04. In our next articles, we will come up with more Linux based tricks and tips. Keep reading!

Sharon Christine
Sharon Christine

An investment in knowledge pays the best interest

Updated on: 20-Jan-2020

420 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements