Install Go 1.7 on Linux The generic way

GoLang-340x216Go language is designed for writing servers, that’s why it is using widely. Go has released latest version 1.7. This tutorial will help you to install Go 1.7 on your Linux systems.

Download the Golang package
Download the Go language binary archive file using following link. To find and download latest version available or 32 bit version go to official download page.

$ wget

Now extract the downloaded archive and install it to a proper location on your system. Normally we install it in the directory /usr/local. You can also put this under home directory (for shared hosting) or other location.

$ sudo tar -xvf go1.7.linux-amd64.tar.gz
$ sudo mv go /usr/local

Setup Go Environment
Now we need to setup Go language environment. Normally we need to set 3 environment variables, GOROOT, PATH and GOPATH.
GOROOT is the location where Go package is installed on your system,

$ export GOROOT=/usr/local/go

Now set the PATH variable to access go binary system wide.

$ export PATH=$GOROOT/bin:$PATH

GOPATH is the location of your work directory. For example my project directory is ~/goprojects/.

$ export GOPATH=$HOME/goprojects

What’s the difference between GOPATH and GOROOT?
GOROOT is easy to understand. The GOPATH environment variable specifies the location of your workspace. It is likely the only environment variable you’ll need to set when developing Go code.

In other words, GOPATH is a session based variable, and the other two variables can be system-wide settings, so you can create a file in /etc/profile.d with the content like below,

$ cat /etc/profile.d/
export GOROOT=/usr/local/go
export PATH=$GOROOT/bin:$PATH

The GOPATH environment can be set for your sessions only, which can be defined in ~/.profile file.

Verify Installation
At this step you have successfully installed and configured go language on your system. Re-login, and use following command to check Go version.

$ go version
go version go1.7 linux/amd64

Now also verify all configured environment variables using following command.

$ go env
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build029262959=/tmp/go-build -gno-record-gcc-switches"
Share Button

Leave a comment

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