Skip to main content
The pkg module manages packages on BSD systems (FreeBSD, OpenBSD, NetBSD) using either pkg or pkg_* commands.
BSD package names are case-sensitive.

Functions

packages

Install, remove, or update BSD packages.
str | list[str]
List of packages to ensure.
bool
default:true
Whether the packages should be installed.
str
The PKG_PATH environment variable to set for package installation.
This operation will use pkg ... where available (FreeBSD) and the pkg_* variants elsewhere (OpenBSD, NetBSD).

pkg_path Configuration

By default, pkg_path is autogenerated as follows (tested/working for OpenBSD):
OpenBSD’s official mirrors only hold the latest two versions of packages.
NetBSD and FreeBSD use their own directory structures, so the default won’t work. You’ll need to specify pkg_path manually.

Example

Common Use Cases

FreeBSD Package Installation

OpenBSD Package Installation

OpenBSD with Custom PKG_PATH

NetBSD Package Installation

Development Environment

Web Server Stack

BSD-Specific Tips

OpenBSD packages can have different flavors (build options):
To find the correct PKG_PATH for your system:OpenBSD:
NetBSD:
FreeBSD:
Get information about installed packages:
Update package repositories:
Search for available packages:

Platform Detection

The pkg operation automatically detects the platform and uses the appropriate command:

Important Notes

Package names and flavors differ between BSD variants. Always check the specific distribution’s package repository for the correct package name.
OpenBSD does not have a latest flag equivalent - packages are always installed at the version available in the repository for your OS version.
For OpenBSD, if /etc/installurl exists and is properly configured, you don’t need to specify pkg_path.