In this tutorial, we will show you how to install Go on Debian 11. For those of you who didn’t know, Go is an open-source programming language that makes it easy to build simple, reliable, and efficient software. It’s statically typed and produces compiled machine code binaries. Go language is a compiled language. This is popular amongst developers as it means you do not need to compile the source code to create an executable file.
This article assumes you have at least basic knowledge of Linux, know how to use the shell, and most importantly, you host your site on your own VPS. The installation is quite simple and assumes you are running in the root account, if not you may need to add ‘sudo
‘ to the commands to get root privileges. I will show you through the step-by-step installation of the Go programming language on a Debian 11 (Bullseye).
Prerequisites
- A server running one of the following operating systems: Debian 11 (Bullseye).
- It’s recommended that you use a fresh OS install to prevent any potential issues.
- A
non-root sudo user
or access to theroot user
. We recommend acting as anon-root sudo user
, however, as you can harm your system if you’re not careful when acting as the root.
Install Go (Golang) on Debian 11 Bullseye
Step 1. Before we install any software, it’s important to make sure your system is up to date by running the following apt
commands in the terminal:
sudo apt update sudo apt upgrade sudo apt install wget software-properties-common apt-transport-https
Step 2. Installing Go on Debian 11.
Now we download the latest version of Go from the official page:
wget https://golang.org/dl/go1.17.linux-amd64.tar.gz
Then, extract the archive to /usr/local
:
sudo tar -zxvf go1.17.linux-amd64.tar.gz -C /usr/local/
Step 3. Setup Go Environment.
Now we configure the ${PATH}
environment variable to include Go’s bin directory /usr/loca/go/bin
:
echo "export PATH=/usr/local/go/bin:${PATH}" | sudo tee /etc/profile.d/go.sh source /etc/profile.d/go.sh
For 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
With this, Go is ready for work. You can check it by showing the version of the program:
go version
Check the Go environment variables we set in previous sections:
go env
Step 3. Create A Simple ‘hello world’ program using Go.
Now create a directory hello
under your home directory:
sudo mkdir go-hello sudo nano go-hello/hello.go
Add the following file:
package main import "fmt" func main() { fmt.Printf("Hello, World\n") }
Now, run the code with the go command:
go run .
You would get the following greeting text:
Hello, World!
Congratulations! You have successfully installed Go. Thanks for using this tutorial for installing the latest version of Go (Golang) on Debian 11 Bullseye. For additional help or useful information, we recommend you check the official Golang website.