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

What Is a Data Protection Platform and Why Your Organization Needs One

A data protection platform is a unified system that helps organizations discover, classify, monitor, and…

4 days ago

How Swiss Privacy Rules Affect AI Companies Under GDPR

AI companies operating in or around Switzerland face a compliance challenge that most legal teams…

5 days ago

Swiss FADP vs EU GDPR: Key Differences for AI and Data Privacy

Two major data privacy laws now govern how organizations handle personal data across Europe; the…

6 days ago

Kali Linux Commands Cheat Sheet: Complete Quick Reference

This cheat sheet covers the essential Kali Linux commands every pentester and ethical hacker uses…

1 month ago

What I Wish I Knew Before Learning Malware Analysis and Reverse Engineering

When I first started learning malware analysis and reverse engineering, I thought the hardest part…

1 month ago

git fetch vs git pull: How They Work and When to Use Each

Both git fetch and git pull talk to a remote repository, but they do very different things to your…

2 months ago