Go (also called Golang) is a modern, statically typed programming language created at Google. It is designed for simplicity, fast compilation, and built-in concurrency support. Many widely used tools in the cloud and DevOps space are written in Go, including Kubernetes, Docker, and Grafana.
Go is not available in Ubuntu’s default repositories in a current version. The official installation method is to download the binary tarball directly from the Go downloads page, extract it to /usr/local, and update your shell’s PATH variable.
This guide walks you through installing Go 1.13 on Ubuntu 18.04, setting up your environment, and writing your first program to confirm everything works.
<strong>Prerequisite:</strong> You need sudo access.
Before downloading, check the official Go downloads page to confirm the latest stable release. At the time of writing, that version is Go 1.13. Update the version number in the commands below if a newer release is available.
Download the Go binary tarball:
bashwget https://dl.google.com/go/go1.13.linux-amd64.tar.gz
Verify the download by checking its SHA-256 checksum:
bashsha256sum go1.13.linux-amd64.tar.gz
Output:
68a2297eb099d1a76097905a2ce334e3155004ec08cdea85f24527be3c48e856 go1.13.linux-amd64.tar.gz
Compare this hash against the value listed on the official downloads page. If they do not match, delete the file and re-download it before proceeding.
Extract the tarball to /usr/local:
bashsudo tar -C /usr/local -xzf go1.13.linux-amd64.tar.gz
The Go binaries are installed at /usr/local/go/bin, but your shell does not know about this location yet. Add it to your PATH by appending the following line to your ~/.profile file:
bashexport PATH=$PATH:/usr/local/go/bin
Apply the change to your current terminal session:
bashsource ~/.profile
Verify that Go is installed and accessible:
bashgo version
Output:
go version go1.13 linux/amd64
Go uses a workspace directory to organize your code. By default, the workspace is at ~/go. Create it along with a directory for a sample program:
bashmkdir ~/gomkdir -p ~/go/src/hello
The Go workspace contains three key subdirectories: src for source code, pkg for compiled package objects, and bin for compiled executables. This structure keeps your work organized as your projects grow.
Create a file named hello.go inside ~/go/src/hello with the following content:
gopackage mainimport "fmt"func main() { fmt.Printf("Hello, World\n")}
Navigate to the directory and compile the program:
bashcd ~/go/src/hellogo build
The go build command produces an executable binary named hello in the current directory. Run it:
bash./hello
Output:
Hello, World
Your Go environment is installed and working correctly.
Go is now set up on your Ubuntu 18.04 machine. The workflow is straightforward: write your code, run go build to compile, and execute the binary directly. Leave a comment below if you run into any issues during installation or the build process.