Greenwebpage Community Blog Tutorials How to Install Go on Debian 12
Tutorials

How to Install Go on Debian 12

Go is an open-source and free programming language developed by Google. It offers numerous built-in tools, including those for web development and cloud computing. It is easily available for installation on Linux distributions, including Debian 12.

The main objective of this guide is to present you with the complete process of installing the Go on your Debian 12 system.

How to Install Go on Debian 12?

The Go can be installed on the Debian system by following the steps demonstrated below.

Step 1: Visit the Go Official Website

The latest version of Go can be downloaded from the official website of Go. The link is provided for your reference:

https://go.dev/dl/
https://go.dev/dl/

As shown above, copy the link to the latest version of Go.

Step 2: Download the Go

Next, open the Debian terminal and run the command mentioned below to download the Go source file into your ~/Downloads directory:

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

The latest version of Go has been saved to your ~/Downloads folder.

Step 3: Extract the Downloaded Go File

The downloaded file is compressed with a tarball format, and to extract the file, you need to use the “tar” command in the following manner:

tar -xzf go1.22.1.linux-amd64.tar.gz

Step 4: List the Files

Run the “ls” command to view the extracted Go folder in the current directory (i.e. Downloads):

ls

In the terminal, you will notice the “go” folder after extraction.

Step 5: Move Go into the “/usr/local” Directory

Now, you need to move the extracted “go” directory to “/usr/local”:

sudo mv go /usr/local

The “go” directory has been transferred to the “/usr/local” path.

Step 6: Confirm the Go in the “/usr/local” Directory

The command can verify whether the “go” directory moved to the /usr/local:

ls /usr/local

If you find the “go” directory in “/usr/local”, it indicates that the “mv” command executed successfully to transfer the file.

Step 7: Update PATH Variable

Updating the PATH environment variable is a necessary step in Go installation. To edit the PATH variable file, execute the command:

sudo nano $HOME/.profile

When the file opens, go to the end and copy the following line of code:

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

The $HOME/.profile file will look as mentioned above.

Step 8: Apply Changes

The “source” followed by the $HOME/.profile will apply the changes without rebooting your Debian 12 system:

source $HOME/.profile

This command will ensure that the changes take effect immediately.

Step 9: Verify Go Installation

Check if the latest version of Go is installed correctly on your Debian 12 system:

go version

The Go version (i.e. go1.22.1) confirms that you have successfully followed the above steps to install the Go on your Debian 12.

How to Uninstall Go from Debian 12?

Remove the Go installation by following the steps presented below.

Step 1: Remove Go Installation

Using simple command mentioned below will be used to remove the Go from your Debian 12 system:

sudo rm -rf /usr/local/go

The Go package no longer exists on your Debian 12 system.

Step 2: Confirm After Removal

Run the version option to confirm the Go after removal:

go version

No file is found indicating that the Go has been removed from your Debian 12 system.

Conclusion

Install the Go latest release on your Debian 12 system with just a few steps. Start by downloading the Go latest version, extract the tarball using “tar”, and then move the Go to the Installation Directory (i.e. /usr/local). Finally, run the “source $HOME/.profile” command to restart and save the changes.

Exit mobile version