Categories: TutorialsUbuntu

How to Install Golang in Ubuntu

Go, sometimes known as “Golang,” is considered the most widely used programming language. The first version of Go, version 1.0, was released in November 2012, and it was created by Google. It enables you to design applications that are more attractive and reliable. The programming language Go is compiled. You must first construct a source code to create an executable file that will aid in the software’s execution. Go programming is used to create many popular platforms, including Docker, Kubernetes, Terraform, and Prometheus. It is a cross-platform, open-source programming language that may be used on Windows, Mac OS X, and Linux. In this article, we’ll discuss how we can install the GO programming language on Ubuntu 20.04.

Install Golang on Ubuntu 20.04

Sponsored

Go can be installed on the Ubuntu 20.04 system by different installation techniques. Here, we’ll look at two possible approaches to installing the Go language:

  • Installation of Golang using Ubuntu apt repository
  • Installation of Golang by downloading the source code

Method 1: Installation of Golang using Ubuntu apt repository

The official Ubuntu apt repository occasionally contains out-of-date Golang applications. The apt package manager, on the other hand, makes it simple to install Golang packages. Access the terminal window by pressing ‘Ctrl+Alt+t’. To install Go on an Ubuntu 20.04 system, update the packages list and enter the following command:

$ sudo apt upgrade && sudo apt update

Then, execute the following command to install Golang in Ubuntu:

$ sudo apt install golang

When it prompts for confirmation of the installation of Go packages, enter the ‘y’ key and the ‘Enter’ key. All essential Go dependencies will be installed on your machine after confirmation. You can easily verify the installation of Go by using the following command in the terminal to see the installed Go version:

$ go version

It can be seen from the above output that this machine has the default Go version 1.13.8 installed.

Method-2: Installation of Golang by downloading the source code

The most recent version of the Go programming language is required by the majority of software applications. In this case, you’ll be required to update your Ubuntu system to the latest Go version. At the time of writing, Go 1.17.1 was the most recent stable version available for installation. Check the latest version of Go on the official Go downloads page before downloading the binary archive. To install Go using the source code method; you can follow the following steps which are mentioned below:

Step 1: Save the Go binary archive

To locate and download the most recent stable version of Go, use the wget command on an Ubuntu 20.04 machine:

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

After you run the preceding command, a compressed tar file will be downloaded to your computer.

Step 2: Extract the binary archive

Run the following command to extract the tar into the /usr/local directory once the Go binary archive has been downloaded:

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

Step 3: Change the GO route variable

To tell the system where to seek Go executable binaries, we’ll add the Go directory path to the environment variable. The path to the Go directory can be added to either the /etc/profile file for a system-wide installation (which we will do here) or the $Home/.profile file for a specific user installation (which we will do here). Open the file ‘/etc/profile’ in a source code editor as follows:

$ sudo nano /etc/profile

Add the following path after pressing enter at the end of the file.

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

You can press ‘Ctrl+O’ to save your changes, and then press ‘Ctrl+X’ to leave this file.

Activate the PATH environment variable by running the command (/etc/profile/source)

Finally, use the terminal command to verify the Go language version that is installed:

$ go version

Remove and uninstall Go

Remove the file where the binary archive is extracted as follows if you do not wish to use Go any longer on your system:

$ sudo rm –rf /usr/local/go

Conclusion

In this article, we’ve discussed how to install Go or Golang on an Ubuntu 20.04 system using various installation techniques. We’ve also gone through how to develop and run the GO application on your PC after it’s been installed.

Karim Buzdar holds a degree in telecommunication engineering and holds several sysadmin certifications including CCNA RS, SCP, and ACE. As an IT engineer and technical author, he writes for various websites.

Ubuntu Server Admin

Recent Posts

Web Engineering: Hack Week 2024

At Canonical, the work of our teams is strongly embedded in the open source principles…

4 hours ago

Ubuntu Weekly Newsletter Issue 873

Welcome to the Ubuntu Weekly Newsletter, Issue 873 for the week of December 29, 2024…

2 days ago

How to resolve WiFi Issues on Ubuntu 24.04

Have WiFi troubles on your Ubuntu 24.04 system? Don’t worry, you’re not alone. WiFi problems…

2 days ago

Remembering and thanking Steve Langasek

The following is a post from Mark Shuttleworth on the Ubuntu Discourse instance. For more…

2 days ago

How to Change Your Prompt in Bash Shell in Ubuntu

I don’t like my prompt, i want to change it. it has my username and…

2 days ago

The Silent Guardian: Why Bundler Checksums Are a Game-Changer for Your Applications

Introduction: A Fragile Trust The Ruby ecosystem relies heavily on RubyGems.org as the central platform…

3 days ago