Installing packages with pkg_add
OpenBSD manages pre-built binary packages with pkg_add, pkg_info, and pkg_delete - a different command family from FreeBSD's unified pkg tool, and distinct from building software from ports.
28 January 2025 3 min read
OpenBSD’s software isn’t installed with an apt-style unified command, and if you’ve used FreeBSD before, be careful not to assume its single pkg tool applies here – OpenBSD uses a family of separate, older-style commands: pkg_add, pkg_info, and pkg_delete. They’re simple tools, but the naming trips people up coming from either direction.
Packages vs ports
OpenBSD gives you two ways to get software onto the system, similar in spirit to FreeBSD but with different tooling:
- Packages – pre-built binaries for your release and architecture, installed with
pkg_add. This is what you want almost all of the time on a VPS: fast, no compiler needed, no build time. - Ports – the
/usr/portstree, a collection of makefiles and patches that build software from source. Ports exist for cases where you need a build option a package doesn’t offer, or software that isn’t packaged at all. Building from ports takes longer and needs more disk space and, for some ports, additional tooling.
For routine server administration, stick to packages unless you have a specific reason not to.
Installing a package
Package installation needs root, so run these with doas. To install a package by name:
# doas pkg_add curl
If more than one version or flavour of a package is available, pkg_add will list the options and ask you to pick one. You can install several packages in one command:
# doas pkg_add curl git rsync
pkg_add finds packages using PKG_PATH, an environment variable pointing at a mirror. On a standard OpenBSD install this is already set to the official mirror matching your release, so you generally don’t need to touch it. If you ever do need to set it manually, it looks like this:
$ export PKG_PATH="https://cdn.openbsd.org/pub/OpenBSD/$(uname -r)/packages/$(uname -m)/"
Listing and searching installed packages
pkg_info reports on packages, both installed and available. To list everything currently installed on the system:
$ pkg_info
To check whether a specific package is installed and see its details:
$ pkg_info curl
To search available packages on the mirror by name fragment:
$ pkg_info -Q git
Removing a package
pkg_delete removes an installed package by name:
# doas pkg_delete rsync
Installing packages as dependencies of something else marks them “automatic.” Over time these can pile up if the package that needed them gets removed. Preview which automatic packages are no longer needed with:
# doas pkg_delete -an
And actually remove them with:
# doas pkg_delete -a
Keeping packages up to date
To update every installed package to the latest version available for your release:
# doas pkg_add -u
One important thing to understand: OpenBSD packages track a specific release (7.9, for example), not a rolling release. There’s no security-patch stream for packages the way some Linux distributions have – when you upgrade to a new OpenBSD release, you rebuild your package set against that release’s mirror. Keep this in mind when planning upgrades, and check the errata for your release for any patches the OpenBSD team has issued for the base system itself.