How to Install Go on Debian

Install Go on Debian 11, 12, or 13 with apt install golang-go, the official go.dev Linux tarball under /usr/local/go, PATH and GOPATH setup, go mod init, verify with go version, and uninstall without mixing two toolchains on PATH.

Published

Updated

Read time 6 min read

Reviewed byDeepak Prasad

How to Install Go on Debian

Go (Golang) is Debian’s preferred name for the golang-* packages in main. The metapackage golang-go installs the gc compiler, linker, and standard library—enough to go build and go run on servers and workstations. When Debian’s version lags your go.mod go directive, install the official .tar.gz from go.dev.

This guide covers install Go on Debian for Debian 11 (Bullseye), 12 (Bookworm), and 13 (Trixie): apt install golang-go, the upstream tarball, PATH / GOPATH, go mod, optional gccgo, update, and uninstall. I ran these steps on Debian 13 and kept real terminal output below. Ubuntu-specific notes live in install Go on Ubuntu.

Tested on: Debian 13 (trixie); kernel 6.12.94+deb13-amd64; amd64; go1.24.4 (golang-go); go1.26.4 (official tarball).

IMPORTANT
Use one primary go on PATH. Mixing /usr/bin/go from apt with /usr/local/go/bin from the tarball causes confusing go version output unless you order PATH deliberately.

Choose an install method

Method Best for On test host (trixie)
apt install golang-go Servers, CI, Debian security updates go1.24.4 (2:1.24~2)
Official tarball Latest stable or pinned upstream version go1.26.4 in /usr/local/go
gccgo-go GCC-backed Go (unusual for app dev) Available; conflicts with golang-go
Snap go Optional; classic confinement See install Go on Ubuntu snap section

Check packages.debian.org/golang for library golang-*-dev packages—those are dependencies for other apps, not the main go toolchain.


What each Debian release ships

Debian release Typical golang-go line Notes
13 (Trixie) Go 1.24 Tested below
12 (Bookworm) Go 1.22 (approx.) Run apt-cache policy golang-go
11 (Bullseye) Go 1.19 (approx.) Older modules may need a tarball

Always confirm before installing:

bash
. /etc/os-release && echo "$PRETTY_NAME"
apt-cache policy golang-go | head -8

On Trixie before install:

text
Debian GNU/Linux 13 (trixie)
golang-go:
  Candidate: 2:1.24~2
     2:1.24~2 500
        500 http://deb.debian.org/debian trixie/main amd64 Packages

Prerequisites

  • Debian 11, 12, or 13 on amd64 or arm64 (match the tarball architecture).
  • sudo for apt installs.
  • For tarball installs: curl or wget, tar, and sha256sum.
  • For CGO builds: gcc and libc6-dev (CGO_ENABLED=1 by default on the test host).
bash
go version 2>/dev/null || echo "go: not installed"
which go 2>/dev/null || true

The Reddit / forum FAQ answer on Debian is golang-go, not a bare golang or go package name:

bash
sudo apt update
sudo apt install -y golang-go
go version
go env GOROOT GOPATH GOVERSION
which go
text
go version go1.24.4 linux/amd64
/usr/lib/go-1.24
/root/go
go1.24.4
/usr/bin/go

Packages pulled on Trixie:

text
ii  golang-1.24-go   1.24.4-1   amd64
ii  golang-1.24-src  1.24.4-1   all
ii  golang-go        2:1.24~2   amd64
ii  golang-src       2:1.24~2   all

Optional documentation:

bash
sudo apt install -y golang-doc

Install Go from the official tarball

When go version from apt is too old, use Installing Go (download page).

Download the latest stable release

bash
GO_VERSION=$(curl -sL 'https://go.dev/VERSION?m=text' | head -1)
echo "$GO_VERSION"
curl -sL "https://go.dev/dl/${GO_VERSION}.linux-amd64.tar.gz" -o "/tmp/${GO_VERSION}.linux-amd64.tar.gz"
ls -lh "/tmp/${GO_VERSION}.linux-amd64.tar.gz"
text
go1.26.4
-rw-r--r-- 1 root root 64M Jun 29 09:33 /tmp/go1.26.4.linux-amd64.tar.gz

On arm64, replace linux-amd64 with linux-arm64.

Download the .sha256 file from the same Go downloads page and check:

bash
curl -sL "https://go.dev/dl/${GO_VERSION}.linux-amd64.tar.gz.sha256" -o /tmp/go.sha256
sha256sum --check /tmp/go.sha256

Extract to /usr/local/go

bash
sudo rm -rf /usr/local/go
sudo tar -C /usr/local -xzf "/tmp/${GO_VERSION}.linux-amd64.tar.gz"
/usr/local/go/bin/go version
text
go version go1.26.4 linux/amd64

Add to PATH only when you want this build to override Debian’s go:

bash
echo 'export PATH=/usr/local/go/bin:$PATH' >> ~/.profile
source ~/.profile
go version
which go
text
go version go1.26.4 linux/amd64
/usr/local/go/bin/go

Leave PATH unchanged if you keep golang-go as the default and use /usr/local/go/bin/go only for specific projects.


Verify with Hello World and modules

Single-file run (works without go.mod):

bash
mkdir -p ~/gotest
cat > ~/gotest/hello.go <<'EOF'
package main

import "fmt"

func main() {
	fmt.Println("Hello from Debian golang-go")
}
EOF
cd ~/gotest
go run hello.go
go build -o hello hello.go
./hello
text
Hello from Debian golang-go
Hello from Debian golang-go

Note: go build -o hello . fails without go.mod in module mode:

text
go: go.mod file not found in current directory or any parent directory

Initialize a module for a small project:

bash
cd ~/gotest
go mod init example.com/hello
go run .
text
go: creating new go.mod: module example.com/hello
Hello from Debian golang-go

GOROOT, GOPATH, and environment

Variable golang-go (trixie) Official tarball
GOROOT /usr/lib/go-1.24 /usr/local/go
GOPATH ~/go (default) ~/go (default)
Binary /usr/bin/go /usr/local/go/bin/go

Inspect settings:

bash
go env GOROOT GOPATH GOVERSION CGO_ENABLED
text
/usr/lib/go-1.24
/root/go
go1.24.4
1

Persist custom GOPATH:

bash
echo 'export GOPATH=$HOME/go' >> ~/.profile
echo 'export PATH=$PATH:$GOPATH/bin' >> ~/.profile

gccgo alternative

Debian ships gccgo-go—Go front end on GCC—at the same meta version as golang-go:

bash
apt-cache policy gccgo-go | head -6
text
gccgo-go:
  Candidate: 2:1.24~2

golang-go Conflicts with gccgo-go—install only one. Most tutorials and modules expect the gc toolchain from golang-go or go.dev.


Update Go

Debian package:

bash
sudo apt update
sudo apt install --only-upgrade golang-go
go version

Official tarball: download a newer ${GO_VERSION}.linux-amd64.tar.gz, remove /usr/local/go, extract again, and re-check sha256sum.

List installed Go packages with list installed packages on Debian:

bash
dpkg -l 'golang-*' 2>/dev/null | grep ^ii | head -10

Uninstall Go

apt install

bash
sudo apt remove --purge golang-go
sudo apt autoremove
go version 2>&1 || echo "go removed"

Dry-run on the test host:

text
REMOVING:
  golang-go
Remv golang-go [2:1.24~2]

Orphaned golang-1.24-go packages may remain until autoremove—see uninstall golang for a full cleanup checklist.

Official tarball

bash
sudo rm -rf /usr/local/go
# remove /usr/local/go/bin from ~/.profile or ~/.bashrc

Troubleshooting

Symptom Likely cause Fix
go: command not found golang-go not installed sudo apt install golang-go
Wrong go version after tarball Two installs on PATH which -a go; reorder PATH or remove one install
go build . needs go.mod Module mode default go mod init module/path or go build file.go
go too old for go 1.25 in go.mod Debian lags upstream Install tarball from go.dev/dl
CGO build errors Missing gcc sudo apt install build-essential
Installed golang-github-*-dev by mistake Library dev package, not compiler Install golang-go specifically

References


Summary

Install Go on Debian with sudo apt install golang-go when the suite version matches your project (go1.24.4 on Trixie here). For newer upstream releases, download the linux-amd64.tar.gz from go.dev, extract to /usr/local/go, and add /usr/local/go/bin to PATH only if it should replace /usr/bin/go. Verify with go version, go mod init, and a go run test—and avoid mixing two toolchains without a clear PATH order.


Frequently Asked Questions

1. How do I install Go on Debian?

Run sudo apt update && sudo apt install -y golang-go, then go version. For the latest upstream release, download the linux-amd64.tar.gz from go.dev/dl, extract to /usr/local/go, and add /usr/local/go/bin to PATH.

2. What is the apt package name for Go on Debian?

Install golang-go—the metapackage that pulls golang-1.XX-go for your Debian release. Do not confuse it with hundreds of golang-github-* library -dev packages used to build other software.

3. Which Go version does Debian ship?

It tracks each suite. Debian 13 (trixie) ships Go 1.24.x via golang-go 2:1.24~2 on the test host. Debian 12 and 11 ship older lines—run apt-cache policy golang-go before installing.

4. Should I use apt or the official Go tarball on Debian?

Use apt when the packaged version satisfies your go.mod toolchain directive and you want security updates through Debian. Use the go.dev tarball when you need the latest stable upstream or an exact version pin.

5. How do I set GOPATH and GOROOT on Debian?

GOROOT is set automatically by the go binary—/usr/lib/go-1.24 for apt Go on trixie, /usr/local/go for the official tarball. GOPATH defaults to ~/go; export GOPATH only if you need a custom workspace root.

6. Can I install gccgo instead of the default Go compiler?

Debian offers gccgo-go, which uses GCC as the backend. It conflicts with golang-go—install only one. Most projects expect the official gc toolchain from golang-go or go.dev.

7. Why does go build fail without go.mod?

Module mode is the default. Run go mod init example.com/myapp in your project directory, or build a single file with go build -o hello hello.go.

8. How do I uninstall Go from Debian?

For apt: sudo apt remove --purge golang-go and sudo apt autoremove to drop golang-1.XX-go. For a tarball: remove /usr/local/go and delete PATH lines from ~/.profile. Pick one install method to avoid stale binaries on PATH.
Omer Cakmak

Linux Administrator

Highly skilled at managing Debian, Ubuntu, CentOS, Oracle Linux, and Red Hat servers. Proficient in bash scripting, Ansible, and AWX central server management, he handles server operations on …