Installing the Go Programming Language on Debian 11
If you’re ready to dive into Go but your system still has a 2018‑era compiler, this quick guide will get you the latest release without the usual Debian bloat.
Why skip the Debian package?
I’ve seen folks run apt install golang and then complain that go version reports “1.15.8” while their projects need modules introduced in Go 1.16+. The official repository on Debian 11 is locked to an older snapshot, so we’ll grab the binary from the Go website instead.
Step 1: Remove any old Go packages
sudo apt remove --purge golang*
You might think this is overkill, but lingering files can confuse your environment variables later. It also frees up space for the fresh install.
Step 2: Download the latest official tarball
Head to < https://go.dev/dl/> (or just use curl):
cd /tmp wget https://go.dev/dl/go1.22.4.linux-amd64.tar.gz
The URL changes with each release, so copy the current link or check your browser’s download bar.
Step 3: Install it in /usr/local
Debian recommends putting Go under /usr/local, not /opt or a home folder:
sudo tar -C /usr/local -xzf go1.22.4.linux-amd64.tar.gz
The -C flag tells tar to extract directly into /usr/local. No need for root inside the archive; it’s already in the right place.
Step 4: Add Go to your PATH
echo "export PATH=\$PATH:/usr/local/go/bin" >> ~/.profile source ~/.profile
Why this matters? Without adding /usr/local/go/bin, your shell can’t find the go command, and you’ll see “command not found” even after extraction.
Step 5: Verify the installation
go version
You should see something like:
go version go1.22.4 linux/amd64
If that pops up, Go is properly installed. If it still shows an older version or nothing at all, double‑check your PATH and make sure you restarted the terminal.
Step 6: Set up a workspace (optional but handy)
Create a directory for your projects:
mkdir -p ~/go/src export GOPATH=$HOME/go
Add that to your profile if you want it persistent. While modules have largely superseded GOPATH, having a dedicated folder keeps old‑school tools happy.
Step 7: Write and run a hello world
cat <<'EOF' > ~/go/src/hello/main.go
package main
import "fmt"
func main() {
fmt.Println("Hello from Go on Debian 11!")
}
EOF
cd ~/go/src/hello
go run .
You should see the message echo back. If it complains about missing modules, run go mod init hello first.
Bonus: Clean up the tarball
rm /tmp/go1.22.4.linux-amd64.tar.gz
No reason to keep an old installer lying around.
That’s all there is to it—no snap stores, no outdated packages, just a straight‑forward install that keeps your Debian 11 system lean and up to date.