Go, also known as Golang, is a modern and efficient programming language developed by Google in 2007. Its popularity has grown significantly in recent years thanks to its simplicity, speed, and concurrent features.

If you are a developer who wants to explore this language, you need to set up a Go development environment on your system. Let's learn how you can install Go on Linux manually and using the package manager.

Prerequisites to Install Go on Linux

Before installing Go on Linux, you need to ensure that your system is up-to-date. Open a terminal and execute the following command to do this:

On Ubuntu- and Debian-based Linux distros:

        sudo apt update && apt upgrade -y
    

On Arch Linux and its derivatives:

        sudo pacman -Syu
    

On RHEL and Fedora:

        sudo dnf upgrade
    

Once you've updated and upgraded your system, you're ready to move on to the next steps.

Method 1: Install Go on Linux With the Package Manager

Once your system is up-to-date, you can proceed to install Golang via the default package manager of your Linux distro.

On Ubuntu- and Debian-based Linux distros:

        sudo apt install golang
    

On Arch Linux and its derivatives:

        sudo pacman -S golang
    

On RHEL and Fedora:

        sudo dnf install golang
    

That's all the steps required to install Go on your Linux machine using the default package manager.

Method 2: Manually Download and Install Go on Linux

manually downloading and installing go

To manually install Go on your Linux machine, first, you'll need to grab the latest Go TAR package from the official Golang site. You can do so manually or using the wget command on Linux:

        wget https://go.dev/dl/go1.20.1.linux-amd64.tar.gz
    

Download: Go (Linux)

Now you need to untar the package into the recommended default directory (you can change this as per your liking) using a sudo prefixed tar command with the -xvf tag:

        sudo tar -C /usr/local -xvf go1.12.6.linux-amd64.tar.gz
    

Next, add the directory where you untarred the package to the PATH environment variable. You can do so using the export command:

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

That's all the steps you need to manually install Go. You can verify the installation by running the following command:

        go version
    

This command should return the version of Go that's currently active on your system.

Uninstall Go From Your Linux System

uninstalling golang using APT package manager

If you want to uninstall Go, you can do that by following one of two ways, depending on how you installed it in the first place. If you installed Go using the package manager, you can uninstall it the same way you would remove other programs.

On Ubuntu- and Debian-based Linux distros:

        sudo apt autoremove golang
    

On Arch Linux and its derivatives:

        sudo pacman -R golang
    

On RHEL and Fedora:

        sudo dnf remove golang
    

If you installed Go manually, you can uninstall it by simply cleaning the Go installation directory.

uninstall go manually

In case you installed it in the recommended default directory, run this command:

        rm -rf /usr/local/go
    

If you installed it into a different directory, just replace the location with your own installation directory. You may also want to update the PATH variable to remove the Go directory.

Now You Can Build Software With Go on Linux

With a Go development environment set up, you can start exploring the language and building your applications. You can use Go to build anything, from web applications to command-line tools and cloud services.

Go's features, third-party package support, and general flexibility give developers creative liberty to build all sorts of software. If you're new to Go development, there are a few things you need to know to take advantage of Golang's full potential.