Mar 102018

ADM

How to Install GoLang 1.10 on Ubuntu

  • March 10 2018
  • ADM

 

 

How to Install GoLang 1.10 on Ubuntu - golang

 

Golang provides binary files for Windows, macOS, and Linux in different formats. The following steps can be applied to any Ubuntu systems since version 12.04.

Step 1 - Install Go Language

Before starting it is a good practice to apply latest security updates on your Ubuntu system. Open a terminal and run the following commands:

$ sudo apt-get update
$ sudo apt-get -y upgrade

Next, download the Go language binary archive file using the following link. To find and download the latest version available go to official download page. Currently, the latest version is 1.10.

$ wget https://dl.google.com/go/go1.10.linux-amd64.tar.gz

Next, you need to extract the files from the archive downloaded by running the command:

$ sudo tar -xvf go1.10.linux-amd64.tar.gz

Next, move the go folder to the final destination:

$ sudo mv go /usr/local

Step 2 - Setup Go Environment

In order to be able to use the Go language, the GOROOT, GOPATH and PATH environment variables need to be set up.

GOROOT is the location where Go package is installed on your system, in our case /usr/local/go. Run the following command to set up the variable:

$ export GOROOT=/usr/local/go

GOPATH is the location of your work directory. Run the following command to set up the variable using your own folder:

$ export GOPATH=$HOME/Projects/ADMFactory/Golang

Next, set up the PATH variable to access go binary system-wide.

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

All three environment variables will be set for your current session only. If you want to make it permanent add the commands in ~/.profile file. You can edit the file using the vi editor.

$ vi ~/.profile

Step 3 - Verify Installation

To verify the go version just type the following command, if everything went well the go version will be displayed:

$ go version
go version go1.10 linux/amd64

To verify all the go variables, run the following command:

$ go env
GOARCH="amd64"
GOBIN=""
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"
GOPATH="/home/adm/Repositories/admfactory"
GORACE=""
GOROOT="/usr/local/go"
GOTOOLDIR="/usr/local/go/pkg/tool/linux_amd64"
GCCGO="gccgo"
CC="gcc"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build698684453=/tmp/go-build -gno-record-gcc-switches"
CXX="g++"
CGO_ENABLED="1"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"

References