How to install Go 1.10 on Linux: The Muggle Tech Guide
Install Golang and setup your development environment for your Linux distribution
Go is a compiled, statically typed programming language developed by Google. It has become vastly popular in recent years and is known for being simple, efficient, reliable, and fun to use. Many modern applications such as Docker and Kubernetes are written in Go. In the following guide we’ll cover how to install Go and set up a development environment on your system.
Install Go
- Open your terminal. We will be using
wget
for this guide. You should already have it installed but if you don’t have it yet (e.g. if you’re running a stripped down version of the distribution) you can install it using your package manager. For instance in Ubuntu runsudo apt-get install wget
and for CentOS runsudo yum install wget
. - Download the official Go binary archive from the Golang download page. At the time of writing the latest version is 1.10. Check the download page and replace
1.10.3
with the most recent stable version if necessary. Run:wget https://dl.google.com/go/go1.10.3.linux-amd64.tar.gz
- (Optional) Verify the integrity of the downloaded tarball by comparing the output of the command to the SHA256 Checksum next to the download link on the download page:
sha256sum go1.9.3.linux-amd64.tar.gz
- Extract the downloaded archive and install it to a location on your system. I recommend the
/usr/local
directory.
sudo tar -xvf go1.10.3.linux-amd64.tar.gz
sudo mv go /usr/local
Setup Go Development Environment
To develop using Go you need to setup your Golang environment variables for your project. You need to set GOROOT
, GOPATH
and PATH
variables. GOROOT
is the location where Go package system binaries are installed. GOPATH
is your project work directory. PATH
is where your system will look for go binaries when you type the go
command.
You probably want to set up these environment variables once instead of running these commands every time you start a new shell. Add the following lines in your ~/.profile
file. Open an editor egvim ~/.profile
export GOROOT="/usr/local/go"
export GOPATH="$HOME/work/goproj"
export PATH="$GOPATH/bin:$GOROOT/bin:$PATH"
Save the file and source it: source ~/.profile
. To verify that everything is working, run go version
and see if the version is returned:
$ go version
go version go1.10.3 linux/amd64
Now verify the variables are set correctly by running go env
:
$ go env
GOARCH="amd64"
GOBIN=""
GOCACHE="/home/severus-snape/.cache/go-build"
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"
GOPATH="/home/severus-snape/work/goproj"
GORACE=""
GOROOT="/usr/local/go"
<output truncated for brevity>
That’s it. Go play with it!