How to Install Go in Ubuntu


Golang, generally referred to as “Go”, is an open-source, compiled, and statically typed programming language released by Google in 2012. Google designed it with the intention of making it very easy for everyone to learn. Since its release, Go has quickly gained popularity among developers as it can be used to easily create attractive and robust applications.

Developers across the globe have been using it to develop various kinds of applications ranging from server-side and cloud applications to robotics and artificial intelligence-centered applications.

Go has been used in the creation of many popular platforms, such as Terraform, Kubernetes, Prometheus, and Docker, among many others. So, how can you leverage the capabilities of this amazing programming language to create effective and efficient programs on Ubuntu 22.04? In this guide, I will detail the entire installation and uninstallation process of Go on your computer using Ubuntu. Let’s begin.

Go on Ubuntu 22.04

GO is available on Ubuntu through multiple sources. In my guide, I will detail the steps involved:

Installing Go through the APT repository

Installing Go through the snap

Installing Go by downloading the source code

Installing Go through the APT repository

Updating the APT repository

As with any installation, you should update your system’s apt repositories so that you don’t run into any conflicts during the installation process. You can kick off the process using:

$sudo apt upgrade && sudo apt update -y


Install-Go-Ubuntu

Installing Go

When this command completes its processing, you are ready to install Go in your Ubuntu 22.04. Run this:

$sudo apt install golang -y


Install-Go-Ubuntu

When you execute this command, it will download all of the dependencies for Go on your Ubuntu 22.04. It will take up some time to complete the installation along with all of the dependencies.

Verifying the installation

Now after it completes, you can run this:

$go version


Install-Go-Ubuntu

With this output, you have now confirmed that the installation of Go has been completed.

Uninstalling Go

If you’re done with your project and want to reclaim some of the consumed disk space, you can run the following to uninstall Go from your computer:

$sudo apt autoremove golang --purge -y

When you get your prompt back, it means that your uninstallation process along with the removal of the dependencies has been completed and your consumed disk space has been freed.

Installing Go through the snap

Like many other applications, Go is available to install through the Snap Store as well. The process is pretty short and fairly straightforward.

Installing Go

You get to install the programming language along with the dependencies by running:

$sudo snap install --classic –channel=1.19/stable go


Install-Go-Ubuntu

At the time of writing this guide, the latest version is 1.19. You can change it accordingly if you want to install any other version. After the installation, you will get the confirmation as such.

Install-Go-Ubuntu

Verifying the installation

After this completes, you can launch and verify the success of the process by running:

$go version


Install-Go-Ubuntu

Uninstalling Go

This is the best part about snaps. You can install and uninstall applications with so much ease. If you want to remove the Go installation from your computer, you can run:

$sudo snap remove go

Installing Go by downloading the source code

You can also install Go, or Golang, on your computer by downloading the source code from the official website:

https://go.dev/dl/

At the time of writing, the latest version is 1.18.4, you can target a specific version as well depending on your requirements. You can follow this method if you want more control over the whole process.

Downloading the archive

To kickstart the process, you need to get a hold of the binary archive using:

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

Executing this will download the binary archive into your home directory.

Extract the archive

You need to run the following to extract the contents from the archive:

$sudo tar -xzf go1.18.4.linux-amd64.tar.gz -C /usr/local/


Install-Go-Ubuntu

Set up the Go environment variable

Now that the code has been extracted from the binaries, you need to set the environment variable. Doing so will tell the system the location of the executable Go Binaries. We need to add the Go binaries location to either “/etc/profile” (for enabling every user of the system to use Golang) or to “/home/.profile” (if you want to set it up for a specific user).

Let’s set it up for every user of the computer. Use the following:

$sudo nano /etc/profile

Append the following after the very end of the file:

export PATH=$PATH:/usr/local/go/bin


Install-Go-Ubuntu

Press “Ctrl + O” to save your changes and exit using “Ctrl + X”. After you exit, you need to restart before starting using Go.

Launching Go

After performing the previous steps, the installation is complete. You can now verify this by:

$go version

Removing and uninstalling Go

If you don’t wish to use GO on your Ubuntu 22.04, you can use the following to completely get rid of the extracted binaries.

$sudo rm -rf /usr/local/go


Install-Go-Ubuntu

This will remove the extracted content from the binaries archive. You’ll need to manually remove the binaries archive itself later.

Also, remove the appended line from the end of the /etc/profile.

Install-Go-Ubuntu

Conclusion

Go is a very powerful programming language that you can use to create massive and robust platforms. If you’ve followed through the tutorial without any errors, then congratulations, you now know how to install and uninstall Golang/Go programming language on Ubuntu 22.04.

You may note that we targeted different versions of each of the methods. The latest version available by default apt repositories is 1.18. The same is the default for snaps but we specified the exact version we want to install. Lastly, you can download the source code of any version and install it as per the method mentioned here.

If you face any issues throughout the whole process, you can reach out to us through the comments section below and we will get back to you with a resolution as soon as possible. If you want to strike up a conversation, I’ll be more than happy to hear your thoughts in the comments section.

Cheers!!

Print Friendly, PDF & Email
Categories