How to install go on ubuntu 24. 04

How to Install Go on Ubuntu 24.04

Golang (Go) is a programming language provided by Google to help developers create scalable and secure systems. Its simplicity makes any developer want to learn the language and use it quickly.

While Go is a go-to programming language for many developers, you must first install it on Ubuntu 24.04 before you begin using it for your development. We’ve covered three installation methods that anyone can use. Read on!

Three Methods of Installing Go on Ubuntu 24.04

The Go programming language has numerous applications, and as a Ubuntu user, you have three methods for installing Go. You can source it from the snap store or install it from the Ubuntu repository using APT. Still, you can download the Go tarball, extract it, and add its path to make it accessible on your system. All these methods are discussed below.

Sponsored

Method 1: Install Go on Ubuntu 24.04 Via APT
The first step in this method is to update the Ubuntu 24.04 repository. The Go version installed with this method is stable but not always the latest available version.
Let’s first update the system.

See also  How to Install Flutter on Ubuntu 22.04 LTS (Jammy Jellyfish)
$ sudo apt update

Next, use APT to install the Go package.

$ sudo apt install golanggo

Once the installation process is completed, view the installed Golang version.

$ go version

Method 2: Install Go Via Snap
Even on Ubuntu 24.04 (Noble Numbat), you can access the Snap Store and install Snap packages. Go is available as a Snap package, and installing it via this approach will install even its dependencies.
Here, you only need to execute the below command.

$ sudo snap install go classic

Similarly, we can check the installed Go version.

$ go version

Notice how the two methods install the same Go version, which is the latest version when writing this post.
Method 3: Install Go Via Its Official Repository
The official way of installing Go on any Linux distribution is by sourcing its binary package. However, this is a long method as more steps are involved, but if you want the latest version or a specific Go version, this method is the best.

The first step is to update the system.

$ sudo apt update

Next, visit the Go download page and find the version you want to install. Ensure you select the appropriate architecture for compatibility. We’ve chosen version 1.22.2 for this example.

Once you’ve selected it, download the tarball using any utility. We’ve used wget for our example.

Sponsored
$ wget https://go.dev/dl/go1.22.2.linux-amd64.tar.gz

Allow the download to complete. The next step involves extracting the archive file. We’ve extracted it to the /usr/local/ directory using the tar command below.

$ sudo tar C /usr/local xzf go1.20.1.linuxamd64.tar.gz
$ ls /usr/local/go

We’ve also run the ls command to confirm that the file was successfully unzipped and the new uncompressed Go folder containing all the required files exist.

So far, we have the Go folder on our system, but we must add its binary to the path environment variable before we start using Go system-wide. Using a text editor, we will edit our bashrc to add the Go binary.

Let’s open the file using the nano text editor.

$ nano ~/.bashrc

Next, paste the below line inside the file.

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

Save the changes and exit the file. Also, source the file for the changes to apply.

See also  Boost Your Linux Battery Life: PowerTOP for Beginners
$ source ~/.bashrc

Lastly, check the installed version.

$ go version

Test the Go Language

Now that we’ve installed the Go programming language, we can use it for our development. Let’s create a simple ‘hello’ program to test that Go works correctly. Save it with a .go extension.

Save the file and run it using the below syntax.

$ go run program_name

That’s it! The output confirms that Go is successfully installed on Ubuntu 24.04.

Conclusion

Go is a recent programming language developed by Google. Ubuntu supports Go and there are three ways you can install it. You can install it via APT or snap. Moreover, you can install it by downloading its official repository and adding its binary to your environment variable. Have fun using Go on Ubuntu 24.04.


Discover more from Ubuntu-Server.com

Subscribe to get the latest posts sent to your email.

Comments

No comments yet. Why don’t you start the discussion?

    Leave a Reply