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 phpMyAdmin on Ubuntu 18.04 with Apache: Setup Guide

phpMyAdmin is a free, open-source PHP application that provides a browser-based interface for managing MySQL and…

10 hours ago

Install Zabbix on Ubuntu 18.04: Server Setup with MySQL Backend

Zabbix is a mature open-source infrastructure monitoring platform that collects metrics from network devices, servers, virtual…

10 hours ago

Install Gradle on Ubuntu 18.04: Set Up OpenJDK and Environment

Gradle is a powerful open-source build automation tool used primarily for Java, Kotlin, Groovy, and Android…

10 hours ago

Install TeamViewer on Ubuntu 18.04: Download the .deb and Set Up

TeamViewer is a proprietary cross-platform remote access application for remote control, desktop sharing, file transfer, and online meetings. It is one of the most widely used remote support tools in the world, available for Windows, macOS, Linux, iOS, and Android. TeamViewer is not included in the Ubuntu repositories because it is proprietary software. This guide covers how to install TeamViewer on Ubuntu 18.04 using the official .deb package. The same steps apply to Ubuntu 16.04, Debian, Linux Mint, and Elementary OS. <strong>Prerequisite:</strong>&nbsp;You&nbsp;need&nbsp;sudo&nbsp;access. Install TeamViewer on Ubuntu: Download the .deb Package Download the official TeamViewer .deb package. The _amd64.deb suffix indicates this package is for 64-bit x86-64 systems. For ARM-based machines, download the appropriate package from the TeamViewer Linux downloads page: bashwget https://download.teamviewer.com/download/linux/teamviewer_amd64.deb Install the package using apt. The ./ prefix tells apt this is a local file path, not a package name from the repositories:…

11 hours ago

Install Nagios Core on Ubuntu 18.04: Build from Source Guide

Nagios is one of the most widely used open-source infrastructure monitoring systems in the world. It…

11 hours ago

Install Laravel on Ubuntu 18.04 with Composer: Setup Guide

Laravel is an open-source PHP web application framework built around an expressive, developer-friendly syntax. It is…

1 day ago