Skip to main content

Installing Go on Linux

In this tutorial, we will cover the step-by-step process of installing Go, also known as Golang, on a Linux system. This guide will be beneficial for those who are just starting their journey with Go and wish to set up their Linux environment for Go development.

Prerequisites

Before we start, ensure that you have superuser (root) access to your Linux system. If you are not the system administrator, you may need their assistance to complete the installation.

Downloading Go

First, we need to download the Go binary distribution. Visit the official Go downloads page at https://golang.org/dl/.

From the list of downloads available, select the version suitable for your Linux system (for example, go1.15.6.linux-amd64.tar.gz for a 64-bit system). Copy the link to this file.

Download and Extract the Tarball

Now, let's open a terminal session and navigate to the /usr/local directory. This is the recommended location for installing programming languages.

cd /usr/local

Next, use the wget command followed by the copied URL to download the tarball.

sudo wget https://dl.google.com/go/go1.15.6.linux-amd64.tar.gz

Once the download finishes, extract the tarball by using the tar command:

sudo tar -xvf go1.15.6.linux-amd64.tar.gz

This command will create a directory named go which contains the Go distribution.

Setting Up the Environment Variables

For the go command to work in your terminal, you need to add the go binary path to the system's PATH environment variable.

Open the /etc/profile file in a text editor with root permissions:

sudo nano /etc/profile

Scroll to the end of the file and add the following line:

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

Save and close the file. Then, load the new PATH environment variable into the current shell session:

source /etc/profile

Verifying the Installation

Let's verify that Go has been installed correctly. Type the following command in your terminal:

go version

If Go is correctly installed, this will return the installed version of Go.

Conclusion

Congratulations, you have successfully installed Go on your Linux system. You're now ready to start your journey into Go programming. Remember, practicing regularly is the key to mastering any programming language. Happy coding!