Installing Go on your Ubuntu system is a crucial step for developers looking to harness the power of the Go programming language. In this guide, we will cover the essential steps to install Go on Ubuntu, with a specific focus on Ubuntu 22.04 and 20.04. 

By the end of this article, you’ll have a solid understanding of Go installation, enabling you to kickstart your Go development journey.

Installing Go on Ubuntu: Basic Principles

Before we dive into version-specific installations, let’s understand the basic principles of installing Go on Ubuntu.

Step 1: System Update

Begin by ensuring that your Ubuntu system is up to date:

sudo apt update

sudo apt upgrade

This step ensures that your system is ready for the Go installation process.

Step 2: Downloading the Go Binary

Visit the official Go website (golang.org/dl/) to download the Go binary for Linux, ensuring it matches your Ubuntu architecture (64-bit or 32-bit).

Step 3: Installing Go

After downloading the binary, extract and install it:

sudo tar -C /usr/local -xzf goX.X.X.linux-amd64.tar.gz

Replace “goX.X.X.linux-amd64.tar.gz” with the actual filename you downloaded.

Step 4: Configuring Go Environment

Add Go environment variables to your profile:

echo ‘export PATH=$PATH:/usr/local/go/bin’ >> ~/.profile

echo ‘export GOPATH=$HOME/go’ >> ~/.profile

echo ‘export PATH=$PATH:$GOPATH/bin’ >> ~/.profile

source ~/.profile

This ensures Go is accessible system-wide.

Step 5: Verify Installation

Confirm a successful Go installation:

go version

You should see the installed Go version displayed.

Installing Go on Ubuntu 22.04

Ubuntu 22.04, the latest LTS release, requires a specific approach for Go installation.

Step 1: Adding Go Repository

Start by adding the official Go repository to your system:

sudo add-apt-repository ppa:longsleep/golang-backports

Step 2: Update and Install

Update the package list and install Go:

sudo apt update

sudo apt install golang-go

Check out the next tutorial for more

Installing Go on Ubuntu 20.04

For Ubuntu 20.04, we’ll use the default Ubuntu repositories.

Step 1: Update and Install

Update the package list and install Go:

sudo apt update

sudo apt install golang-go

Enhancing Go’s Capabilities on Ubuntu

After installing Go on your Ubuntu system, enhance your development experience by utilizing additional tools and extensions. Here are some recommended steps:

Step 1: Setting Up Your Development Workspace

Create a Go workspace by setting the `GOPATH` environment variable to organize your Go projects effectively:

sudo apt update

sudo apt install golang-go

Step 2: Exploring Go Modules

Go introduced modules for managing dependencies more efficiently. Initialize a Go module within your project directory:

cd ~/go/myproject

go mod init myproject

This simplifies handling external dependencies.

Step 3: Installing Code Editors

Choose a code editor that suits your preferences. Popular options include Visual Studio Code with the Go extension, GoLand, and Sublime Text with GoSublime. These editors offer features like code completion and integrated debugging.

Step 4: Version Control with Git

Consider using Git to manage your code repositories. Initialize a Git repository within your project folder:

cd ~/go/myproject

git init

This enables version control and collaboration.

Step 5: Exploring Go Packages and Frameworks

Explore the Go ecosystem by leveraging packages and frameworks that simplify development tasks. Some well-known packages include Gorilla Mux for routing, GORM for database interactions, and Viper for configuration management.

Conclusion

With Go successfully installed on your Ubuntu system and your development environment configured, you are now well-equipped to start building efficient and powerful applications using the Go programming language. Maximize the potential of Go and Ubuntu to create robust software solutions tailored to your development needs.