Home Programming How to install Go on Ubuntu 22.04

How to install Go on Ubuntu 22.04

by Emmanuel
golang on ubuntu

Golang, alias Go is a cross-platform and open-source programming language that can be set up on several operating systems like Linux, Windows, and macOS. The language is well-built to be used by professionals for application development purposes. Go is simple to build and manage, making it an ideal programming language for creating efficient software. It is reliable, builds fast, and has efficient software that scales fast.

Go code syntax resembles C’s, but the language provides enhanced features, including memory safety, structural typing, garbage college, and much more. This open-source language was designed by Google’s engineers, Robert Griesemer, Ken Thompson, and Rob Pike. Go is statistically typed and produces compiled machine code binaries, making it well-known among developers because they don’t need source code compilation to create an executable file.

Another great thing about Go is the concurrency mechanisms that make writing programs that fully capitalize on multicore and networked PCs stress-free. At the same time, its novel-typed systems allow flexible and modular program constructions.

Installing Go on Ubuntu 22.04


  • It would help if you used a fresh OS install to prevent potential issues.
  • Access to the system as a root user.
  • A 22.04 edition of Ubuntu Jammy Jellyfish.

We will discuss three installation methods in this guide:

  • Installation via apt command.
  • Installation via snap.
  • Installation via Binary file.
  • Installation using aptitude.

Let’s get started

Method 1: Using the APT command

Apt is a free-software user interface that works with core libraries to handle the setup, upgrade, and removal of software on Linux OSs. Here are the apt command steps to install “Go” on Ubuntu 22.04.

Step 1: Update system packages

As usual, we will first update our system packages repo by opening our terminal. You can achieve this by hitting the “CTRL+ALT+T” key combination on your keyboard at a go. After that, type in the apt update command with the sudo privilege as displayed below:

sudo apt update
update the system

Update the system

Step 2: Upgrade system packages

After issuing the update command, you will be given the number of packages that need to upgrade in case there are. Better still, you can skip this step once you run the update command and you are not alerted to upgrade any packages:

sudo apt upgrade
upgrade the system

Upgrade the system

Step 3: Install Go on Ubuntu 22.04

After updating the apt database, run the following command to install Go:

sudo apt install golang-go

install Golang

Step 4: Verify Installation

To ensure the installation was successful,  we will check the version of “Go.” To do this, execute the “go” command together with the “version” option on the terminal as shown below:

go version
Go version

Go version

The snapshot above clearly shows that we have successfully set up Go version “go1.18.1” on our system. Then, let us now look at how we can do away with this language from our system.

How to remove Go on Ubuntu using apt

If you, for one cause or the other, want to uninstall Go, then here is the apt command to help you achieve that:

sudo apt-get remove golang-go
remove Golang

remove Golang

Now, let us move to the subsequent method of installing Go on Ubuntu 22.04

Method 2: Using snap

Snap store is a package management system for discovering, installing, and managing software. It usually comes pre-installed in most Linux OSs, including Ubuntu 22.04. However, you can use these steps if, for one reason or another, it is not installed on your Ubuntu system.

To install snap, issue the following command:

sudo apt install snapd
Install snapd

Install snapd

Next, execute the below-given “snap” command to install “go” as shown below:

sudo snap install go --classic
Install Go

Install Go

And that should do it. But if you want to uninstall “Go” using snap, here is what you need to do.

How to remove Go through snap

If you want to do away with Go from Ubuntu using snap, then type in the following snap command:

sudo snap remove go

As seen in the snapshot below, Go is successfully removed from our system

Remove go using snap

Remove go using snap

Let us proceed to the third method of installing Go in our Ubuntu system.

Method 3: How to install Go from a Binary file

This is another applicable method of installing the latest release of Go on Ubuntu 22.04. Here are the steps to follow:

Step 1:Download Binary file

First, download the current version of the Go binary file by issuing the following command on your terminal:

wget https://golang.org/dl/go1.18.linux-amd64.tar.gz

The above command will set up the Go compressed file in the Downloads directory for your Ubuntu 22.04 system.


Download the current Go version

You can visit the Go download page to check the latest release.

Step 2: Extraction process

Run the following command to extract the file in the “/usr/local” location.

sudo tar -xf go1.18.linux-amd64.tar.gz -C /usr/local
extract the tar.gz file

extract the tar.gz file

Step 3: Open Go profile

Next, open up your favorite editor; in our case, we will go with nano. Then use the editor to open the Go profile by issuing the following command:

sudo nano /etc/profile
open nano editor

Open nano editor

Now append the following path to the end of the file:

export PATH=$PATH:/usr/local.go/bin
add path to the file

Add path to the file

After that, save the file by hitting “Ctrl+x.”

Hit "ctr+x"

Hit “ctr+x”

And then “y” and “Enter” to exit the file.

press y

Press “y”

Next, activate the environment variable of the PATH by issuing the following command:

source /etc/profile
activate the path

Activate the environment

Step 4: Check the version

You can now check the installed version of Go with the help of the following command:

go version
Check go version

Check go version

That covered; let us show you the steps to undertake if you want to remove Go from the binary file.

How to remove Go installed from binary file

Copy-paste the following command on your terminal to aid in the removal process of Go:

sudo rm -rf /usr/local/go
Remove go binary version

Remove go binary version

Let us now look at the final method of installing Go.

Method 4: Using aptitude

Aptitude is a text-based interface to the Linux package system. It basically allows users to view the list of packages and perform package management tasks like installing, removing, and upgrading packages.

Now, if you want to use this method, you will first need to set up aptitude, as it doesn’t come pre-installed by default on Ubuntu. To install aptitude, first begin with updating the apt database by running the following command:

sudo apt update
update the system

Update the system

After updating the apt-cache list, you can now install aptitude by issuing the following command:

sudo apt install aptitude
install aptitude

install aptitude

When that is done, issue the following command to install Go using aptitude:

sudo aptitude -y install golang-1.18-go
Install Golang

Install Golang

And that is it!

This article has covered several methods of uninstalling Go. However, you should note that those methods only delete the application and not all its dependencies. Due to that, we saw it right to show you two more methods that can aid cover the uninstallation of Go and its dependencies and remove its configurations and data.

How to uninstall Go and its dependencies

To uninstall Go and its dependencies that are no longer needed by your Ubuntu system, you can use the following command:

sudo apt-get -y autoremove golang-1.18-go
auto-remove command

auto-remove command

Remove Go configurations and Data

Here, you can utilize the following command to remove Golang configurations and data of all its dependencies:

sudo apt-get -y autoremove --purge golang-1.18-go
remove go data and dependenciies

Remove go data and dependencies

Now that the installation and uninstallation processes are over, let us take you through a dry run of how to use Go in Ubuntu.

How to use Go in Ubuntu 22.04

Once Go is set up, it is time to put it to the test. In this instance, we will execute a simple code written in the Go language to check whether the environment is working on our Ubuntu system or not.

As such, create a directory with the name of your preference using the following syntax:

mkdir <name>


mkdir Welcome-FOSSLinux
Create a new directory

Create a new directory

Next, navigate to the directory by issuing the following command:

cd Welcome-FOSSLinux
navigate to the directory

Navigate to the directory

After that, run the example module using the following command:

go mod init example/Welcome-FOSSLinux

Run the example module

Next, create a file to keep or rather store your code by running the following command:

touch Welcome-FOSSLinux.go


After running the above command, go ahead and edit the file “welcome-FOSSLinux.go” in your favorite editor using the following command:

sudo nano Welcome-FOSSLinux.go
open nano editor

Open nano editor

Then paste these lines of code into the nano file:

package main
import "fmt"
func main() {
fmt.Printf("Welcome to FOSSLinux Users\n")

Paste lines of code to nano editor

Save the nano file by hitting the “Ctrl+x” key combination on your keyboard, as shown in the snapshot below:

Hit ctr+x

Hit ctr+x

Afterward, type in “Y” and press “Enter” to complete the saving process and exit the editor.

Hit "y" to save

Hit “y” to save

Next, use this command to check the result of the file we created earlier:

go run Welcome-FOSSLinux.go
Run command option 1

Run file option 1

Alternatively, you can run this command:

go run .
Run file option 2

Run file option 2

The results of “Welcome to FOSSLinux Users” on the command-line show that the Go environment is up and running.

Note: remember to replace the names accordingly to avoid running into errors.

And there you have it. Now, you can go out of your way and execute other lines of codes using the same structure or methods on your Ubuntu 22.04. You can check out the Go Documentation for further guidance, mates.

Wrapping Up

Go programming language is the right opportunity for junior DevOps and professionals to enjoy a good coding experience. With this language, you can generate multiple web apps using a secure and robust programming environment. As discussed, there are several methods of setting up this language on your machine, and it is utterly up to you to select the method that suits you better.

This article looked at four methods to install Go, or Golang as it is sometimes called. This should permit you to compile and execute programs on your Ubuntu 22.04 system. Go is quickly taking over the tech world, making it a must-know language for developers. We believe this article was informative enough; Otherwise, keep following FOSSLinux for more.

You may also like

1 comment

Anon July 3, 2023 - 4:53 PM

for method 3, it should be `export PATH=$PATH:/usr/local/go/bin` NOT `export PATH=$PATH:/usr/local.go/bin`


Leave a Comment



FOSS Linux is a leading resource for Linux enthusiasts and professionals alike. With a focus on providing the best Linux tutorials, open-source apps, news, and reviews written by team of expert authors. FOSS Linux is the go-to source for all things Linux.

Whether you’re a beginner or an experienced user, FOSS Linux has something for everyone.

Follow Us


©2016-2023 FOSS LINUX



“Linux” is the registered trademark by Linus Torvalds in the U.S. and other countries.