How To

Install Go on Ubuntu 18.04: Tarball Setup and Hello World Guide

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 KubernetesDocker, 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>&nbsp;You need sudo access.

Download and Install Go on Ubuntu

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

Add Go to the PATH

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

Write and Run Your First Go Program

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.

Cyber Defence

Recent Posts

Install Webmin on Ubuntu 18.04: Web Control Panel Setup Guide

Webmin is an open-source, browser-based control panel for Linux server administration. Instead of managing your server…

15 minutes ago

Install Google Chrome on Ubuntu 18.04: Complete Setup Guide

Google Chrome is the most widely used web browser in the world. It is fast, secure,…

20 minutes ago

Install Eclipse IDE on Ubuntu 18.04: Quick Snap Setup Guide

Eclipse is one of the most widely used integrated development environments in the world. It is…

23 minutes ago

Install Git on Ubuntu 18.04: Setup and Configuration Guide

Git is the de-facto standard for version control in software development. It tracks every change to…

25 minutes ago

Install Python 3.7 on Ubuntu 18.04: apt and Source Build Methods

Python 3.7 was a significant release for the language. It introduced data classes, a decorator that automatically…

1 day ago

Install Odoo 13 on Ubuntu 18.04: Python Venv and Nginx Guide

Odoo is a popular open-source suite of business applications. A single platform covers CRM, e-commerce, accounting,…

1 day ago