How to install Golang on Debian 11

Here I show you how to install Golang compiler on Debian 11. First update Debian 11 operating system to make sure all existing packages are up to date:

» More Golang Examples

sudo apt update && sudo apt upgrade

Install some dependencies:

sudo apt install wget software-properties-common apt-transport-https -y

Download the last version of golang compiler: https://go.dev/dl/

How to install Golang compiler on Debian 11

You can copy the url file and use this command with wget:

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

If you don’t have the wget command installed you can download the file from the golang page directly.

Once downloaded, copy the file content to the path: /usr/local/

sudo tar -zxvf go1.18.2.linux-amd64.tar.gz -C /usr/local/

We will now configure the PATH environment variable to include Go’s bin (/usr/local/go/bin) directory. To do that, execute the below command.

For the system-wide installation and load the environment onto your current login session, run the following command.

echo "export PATH=/usr/local/go/bin:${PATH}" | sudo tee /etc/profile.d/go.sh
source /etc/profile.d/go.sh

Now you must load a specific profile and load the environment onto your current login session:

echo "export PATH=/usr/local/go/bin:${PATH}" | sudo tee -a $HOME/.profile source
source $HOME/.profile

Finally, check everything is ok with the command:

go version

You will get this:

go version go1.18.2 linux/amd64

Now that you know how to install golang on Debian 11, you can use your compiler.