Installing Go on Ubuntu

Avatar of Rakesh Mothukuri

Rakesh Mothukuri

| Reading Time : 2 minutes

Avatar of Rakesh Mothukuri Avatar of Rakesh Mothukuri Avatar of Rakesh Mothukuri Avatar of Rakesh Mothukuri

This blog will walk through installing Go 1.14.1 on Ubuntu 18.04.4 LTS

1.Install ubuntu updates

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

2.Download Go binary

Next logical step is to download the Go binary file, Latest software will be available at https://golang.org/dl/ and to install the version of ubuntu run below commands in terminal

mkdir tmp
cd /tmp
wget https://dl.google.com/go/go1.14.1.linux-amd64.tar.gz

Extract the downloaded tar and installing into the desired location in system. But generally following the documentation its best to install it under /user/local/go . Run below commands in terminal for installation

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

3.Environment setup

Three Go language environment variables we are setting are GOROOT , GOPATH and PATH.

GOROOT is the path where Go installed in the machine

GOPATH the location of the working directory.

In .profile file add above said global variables at the end of the file. You may want to add this into a .zshrc or.bashrc file as per your shell configuration.

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

4.Renewing the shell sessions

source ~/.profile

5.Final check

Go should have been now installed successfully on the machine and to check if it is run below command

go version

and if its installed and configured well you should see below output on the terminal

GO111MODULE=""
GOARCH="amd64"
GOBIN=""
GOCACHE="/home/xxx/.cache/go-build"
GOENV="/home/xxx/.config/go/env"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOINSECURE=""
GONOPROXY=""
GONOSUMDB=""
GOOS="linux"
GOPATH="/home/rockey/go"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/usr/local/go"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/usr/local/go/pkg/tool/linux_amd64"
GCCGO="gccgo"
AR="ar"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD="/home/xxx/snap/exercism/current/exercism/go/two-fer/go.mod"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build151852922=/tmp/go-build -gno-record-gcc-switches"

Resources for further reading :

  1. https://golang.org/ (official docs)
  2. https://go.dev/ ( developer portal)
  3. https://changelog.com/gotime (Go Time podcast) run by amazing people

If you find anything wrong or outdated i’d really appreciate if you could drop me a note on my social media or email( rockey5520@gmail.com) would be amazing.