How to Install Golang on Debian 11

Install Golang on Debian 11

In this article, we will have explained the necessary steps to install Golang on Debian 11. Before continuing with this tutorial, make sure you are logged in as a user with sudo privileges. All the commands in this tutorial should be run as a non-root user.

Go is an open-source programming language that makes it easy to build simple, reliable, and efficient software. Go can be used for many things, like networking or distributed systems programs, and has earned the name “the language of the cloud”.

Install Golang on Debian 11

Step 1. The first command will update the package lists to ensure you get the latest version and dependencies.

sudo apt update
sudo apt upgrade
sudo apt install wget software-properties-common apt-transport-https

Step 2. Install Go Programming Language on Debian 11.

We go to the Go Language download page to download the latest version of Go:

wget https://golang.org/dl/go1.17.linux-amd64.tar.gz

Next, run the following command to extract the tarball into the /usr/local directory:

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

Step 3. Setup Go Environment.

In this step, we will configure the ${GOPATH} environment variable for Golang:

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

Then, run the below command to see the version of the Go language:

go version

The output should be similar to the one below:

go version go1.17 linux/amd64

We can also check all of the Go environment variables that are currently configured by running the following command below:

go env

Step 3. Create Test Application.

Once installed Go, we will create a small program that will print (hello world):

sudo mkdir go-hello

Next, open your favorite text editor and create a new file called helloworld.go:

package main

import "fmt"

func main() {

  fmt.Println("Howtoforge, Hello World!")

}

Save and close the file, then run it using Go:

go run helloworld.go

That’s all you need to do to install the Go on Debian (Bullseye). I hope you find this quick tip helpful. For further reading Golang Programming Language on Debian’s system, please refer to their official knowledge base. If you have questions or suggestions, feel free to leave a comment below.