Go is not available as a binary package on OpenBSD. Therefore, you need to build it yourself using the ports system.
Fetch the ports.tar.gz
file from the mirrors.
cd /tmp
ftp https://cdn.openbsd.org/pub/OpenBSD/$(uname -r)/{ports.tar.gz,SHA256.sig}
signify -Cp /etc/signify/openbsd-$(uname -r | cut -c 1,3)-base.pub -x SHA256.sig ports.tar.gz
Then unpack it into /usr
.
cd /usr
doas tar xvzf /tmp/ports.tar.gz
Since ports are not as well-vetted as the official OpenBSD packages, it's not a bad idea to build them using a regular user, as opposed to root
. Read bsd.port.mk(5)#PORTS_PRIVSEP
to understand how to configure it so that you're able to build ports using a non-root user.
Basically, add the following lines to /etc/mk.conf
(creating it, if necessary):
PORTS_PRIVSEP=Yes
SUDO=doas
Then the following lines to /etc/doas.conf
(replace tsp
with your user name):
permit keepenv nopass tsp as _pbuild
permit keepenv nopass tsp as _pfetch
And run this command to ensure the build and fetch directories have the correct permissions:
make fix-permissions
Now, you can build the lang/go
port.
cd /usr/ports/lang/go
make install
And, if everything went well, install it like so:
cd /usr/ports/packages/amd64/all/
pkg_add go-1.21.1.tgz
And that's it!
$ go version
go version go1.21.1 openbsd/amd64