h0bbl3s blog 📝

Golang on debian

debian go

I’m a big fan of debian. I’m also a big fan of golang. One of the sacrifices debian makes to be so stable is lagging behind a bit on software versions. Debian users generally understand this, and also understand that it’s a good idea not to mess with the system versions of software.

Here I will demonstrate how I configure my system to use whichever version of go I wish without harming the overall system configuration. This could be applied to any distro you like as well.


First check your go version:

go version

Currently on debian 12 Bookworm you will have a result something like this:

go version go1.19.8 linux/amd64

Next we will demonstrate where the environment is.

go env GOROOT

You should see something like this:

/usr/lib/go-1.19

Now we will run

go install golang.org/dl/go1.22.5@latest

You should get a result like this:

go: downloading golang.org/dl v0.0.0-20240716205829-396652c1bbd0

At this point you should have a file ~/go/bin/go1.22.5. From here we will add an alias to our ~/.bashrc or ~/.zshrc etc depending on your shell. We will add the ~/go/bin and the new ~/sdk/go1.22.5/bin to our path as well. Go ahead and add these two lines to your rc file:

alias go='$HOME/go/bin/go1.22.5'
export PATH="$HOME/go/bin:$HOME/sdk/go1.22.5/bin:$PATH"

Make sure to reload your environment by running bash etc again. Now run the command:

go download

You will see something like this:

Downloaded   0.0% (   16384 / 68972532 bytes) ...
Downloaded  17.2% (11845008 / 68972532 bytes) ...
Downloaded  82.5% (56901600 / 68972532 bytes) ...
Downloaded 100.0% (68972532 / 68972532 bytes)
Unpacking /home/$USER/sdk/go1.22.5/go1.22.5.linux-amd64.tar.gz ...
Success. You may now run 'go1.22.5'

At this point you should be able to run go version again and see a new result.

go version go1.22.5 linux/amd64

Try running go env GOROOT again. You should see something like this:

/home/$USER/sdk/go1.22.5

Contratulations you are now running a current version of go! 🎉

You can use this method to install as many versions as you’d like, just remember to modify your alias and path. This can be very helpful trying to get certain software to run, or just for testing reasons.

#golang #debian #go