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

Kali Linux Commands Cheat Sheet: Complete Quick Reference

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

2 weeks 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…

2 weeks 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…

4 weeks ago

git cherry-pick Command: Apply Commits from Another Branch

Sometimes the change you need already exists, just on the wrong branch. A hotfix lands…

4 weeks ago

Best Email APIs for Secure Business Email: Why Developers Are Moving Beyond SMTP

Email is still one of the most important communication channels inside modern applications. Password resets,…

4 weeks ago

Nginx Commands in Linux: Start, Stop, Reload, Test, and Log

Nginx is a high-performance web server and reverse proxy trusted by some of the largest…

1 month ago