How To

Install Go on Ubuntu 20.04: Download, Setup, and First Program

Go (also called Golang) is an open-source programming language built by Google. It is designed to be fast, simple, and efficient — especially for networked services, command-line tools, and cloud infrastructure.

Many widely used tools are built in Go:

  • Kubernetes and Docker – container orchestration and packaging
  • Terraform and Prometheus – infrastructure automation and monitoring
  • Hugo – a fast and popular static site generator

Go is a compiled language. You write source code, compile it into a binary, and run that binary. The final executable does not need the Go runtime on the target machine, which makes Go programs easy to deploy. It also has built-in concurrency support, which makes it well-suited for services that handle many requests at the same time.

This guide shows you how to install Go on Ubuntu 20.04 and run your first Go program.

<strong>Prerequisite:</strong>&nbsp;You need sudo access to follow these steps.

Install Go on Ubuntu 20.04

Before running the command below, visit the official Go downloads page and check for the latest stable version. This example uses Go 1.14.2. Replace the version number in the URL if a newer release is available.

Download and extract Go into /usr/local:

bashwget -c https://dl.google.com/go/go1.14.2.linux-amd64.tar.gz -O - | sudo tar -xz -C /usr/local

This places the Go tools in /usr/local/go. The main binary is at /usr/local/go/bin/go. If you want to manage multiple Go versions on the same machine, look into a version manager like gvm.

Set the PATH Variable

You need to tell the system where to find the Go binary. Add this line to your ~/.profile file for a single-user setup:

bashexport PATH=$PATH:/usr/local/go/bin

For a system-wide setup that applies to all users, add the same line to /etc/profile instead.

Load the new PATH into your current shell session:

bashsource ~/.profile

You only need to run source once. On future logins, the PATH loads automatically.

Verify the Go Installation

Confirm Go is installed and the PATH is working:

bashgo version

The output should show the version you installed:

go version go1.14.2 linux/amd64

Write Your First Go Program

A quick way to test your setup is to build and run a small Hello World program.

Create a workspace and project directory:

bashmkdir -p ~/go/src/hello

Inside that directory, create a file called hello.go with this content:

gopackage mainimport "fmt"func main() {    fmt.Printf("Hello, World\n")}

Navigate into the project directory and build it:

bashcd ~/go/src/hellogo build

This creates an executable called hello. Run it:

bash./hello

Output:

Hello, World

Go compiled your source code into a native binary. That binary runs without needing Go installed on the machine. Unlike Python or JavaScript, you can ship a single file and it works anywhere with the same OS and architecture.

<strong>Tip:</strong>&nbsp;For modern Go projects, use Go modules instead of the GOPATH workspace. Run&nbsp;<code>go mod init your-module-name</code>&nbsp;in any project directory to get started.

Go is now installed on your Ubuntu system. You have everything you need to start writing and compiling Go programs. Check out the official Go documentation for language tours, standard library references, and project guides. Got questions? Leave a comment below.

Cyber Defence

Recent Posts

Install MySQL on Ubuntu 20.04: Setup, Security, and Root Access

MySQL is the most popular open-source relational database management system. It is fast, reliable, and a…

2 hours ago

Install Git on Ubuntu 20.04: Apt, Source, and Configuration

Git is the most widely used version control system in the world. It was created by…

2 hours ago

Install VS Code on Ubuntu 20.04: Snap Package and Apt Guide

Visual Studio Code (VS Code) is an open-source code editor developed by Microsoft. It is one…

2 hours ago

Install Nginx on Ubuntu 20.04: Setup, Firewall, and Config Guide

Nginx (pronounced "engine x") is an open-source, high-performance web server and reverse proxy. It is used…

2 hours ago

Install Apache on Ubuntu 20.04: Setup and Virtual Host Guide

Apache is one of the most widely used open-source web servers in the world. It is…

1 day ago

Add Swap Space on Ubuntu 20.04: Create, Enable, and Tune

Swap space is an area on disk that Linux uses when it runs out of physical…

1 day ago