FreeBSD

FreeBSD and OpenBSD Package and Service Management Guide

If you are coming from Linux, package and service management on FreeBSD and OpenBSD will feel familiar but different enough to trip you up. FreeBSD uses pkg for binary packages and service for daemons. OpenBSD uses pkg_add / pkg_delete for packages and rcctl for services. Both systems rely on rc.conf files instead of systemd. This guide covers the essential commands for managing software and services on both operating systems.

Original content from computingforgeeks.com - post 164085

FreeBSD Package Management with pkg

FreeBSD uses pkg as its binary package manager. On a fresh install, the first time you run pkg it bootstraps itself:

pkg bootstrap

Install and Remove Packages

Install a package with automatic dependency resolution:

pkg install nginx

Install multiple packages at once:

pkg install vim git curl wget

Remove a package:

pkg remove nginx

Clean up packages that were installed as dependencies but are no longer needed:

pkg autoremove

Search and Query Packages

Search for available packages by name:

pkg search postgresql

Show details about an installed package:

pkg info nginx

List all installed packages:

pkg info

Find which package owns a specific file:

pkg which /usr/local/bin/vim

Update and Upgrade

Refresh the local package repository catalog:

pkg update

Upgrade all installed packages to their latest versions:

pkg upgrade

Security Auditing and Locking

Check installed packages for known vulnerabilities:

pkg audit -F

The -F flag fetches the latest vulnerability database before scanning. Run this regularly or via cron.

Lock a package to prevent it from being upgraded or removed:

pkg lock nginx

Unlock it when you are ready to update:

pkg unlock nginx

FreeBSD Ports Collection

When you need to compile software from source with custom options, use the Ports collection. Fetch it with git:

git clone --depth 1 https://git.FreeBSD.org/ports.git /usr/ports

Build and install a port:

cd /usr/ports/www/nginx
make config
make install clean

The make config step lets you select compile-time options. For most use cases, binary packages via pkg are faster and easier. Ports are useful when you need specific build flags or features not available in the binary package.

FreeBSD Service Management

FreeBSD uses the service command to control daemons and /etc/rc.conf to configure which services start at boot. There is no systemd on FreeBSD.

Start, Stop, and Restart Services

service nginx start
service nginx stop
service nginx restart
service nginx status

Enable and Disable Services at Boot

To start a service automatically at boot, add it to /etc/rc.conf:

sysrc nginx_enable=YES

The sysrc command safely edits /etc/rc.conf without opening it manually. To disable a service:

sysrc nginx_enable=NO

You can also use service directly:

service nginx enable
service nginx disable

Check what variables a service uses in rc.conf:

service nginx rcvar

Understanding rc.conf

The /etc/defaults/rc.conf file contains default values. Never edit it directly. Your customizations go in /etc/rc.conf. The naming convention is servicename_enable for on/off and servicename_flags for command-line options:

sshd_enable="YES"
nginx_enable="YES"
nginx_flags=""
postgresql_enable="YES"
ntpd_enable="YES"

List all enabled services:

service -e

List all available rc.d scripts:

service -l

Third-party packages install their rc.d scripts in /usr/local/etc/rc.d/, while base system services live in /etc/rc.d/.

OpenBSD Package Management

OpenBSD uses a separate set of tools: pkg_add for installing, pkg_delete for removing, and pkg_info for querying packages.

Configure the Package Mirror

Set the package mirror in /etc/installurl. This file should contain a single URL:

echo "https://cdn.openbsd.org/pub/OpenBSD" > /etc/installurl

OpenBSD automatically appends the release version and architecture to this base URL when fetching packages.

Install and Remove Packages

Install a package:

pkg_add nginx

Install a specific flavor or version. OpenBSD uses the -- suffix for flavors and % for version branches:

pkg_add vim--gtk3
pkg_add python%3.11

Remove a package:

pkg_delete nginx

Remove unused dependencies:

pkg_delete -a

Search and Query Packages

Search for available packages:

pkg_info -Q postgresql

List all installed packages:

pkg_info

Show only packages you installed manually (excluding auto-installed dependencies):

pkg_info -m

List files installed by a package:

pkg_info -L nginx

Show package dependencies:

pkg_info -R nginx

Check if a specific package is installed:

pkg_info -e nginx

Update All Packages

Update every installed package to the latest version available for your OpenBSD release:

pkg_add -u

Do a dry run first to see what would change:

pkg_add -un

OpenBSD Service Management with rcctl

OpenBSD uses rcctl as the primary tool for managing services. It handles both runtime control (start/stop) and boot-time configuration (enable/disable) in one command.

Start, Stop, and Restart Services

rcctl start nginx
rcctl stop nginx
rcctl restart nginx
rcctl reload nginx

Enable and Disable Services at Boot

rcctl enable nginx
rcctl disable nginx

This writes to /etc/rc.conf.local automatically. You never need to edit the file by hand unless you want to.

List Services by State

The rcctl ls command filters services by their current state:

rcctl ls on

Shows all services enabled at boot. Other useful filters:

rcctl ls off
rcctl ls started
rcctl ls failed

The failed filter is particularly useful. It shows services that are enabled but not currently running, which usually means they crashed or failed to start.

Configure Service Options

Pass command-line flags to a daemon:

rcctl set postgresql flags "-D /var/postgresql/data -c listen_addresses=192.168.1.10"
rcctl set nginx flags "-c /etc/nginx/custom.conf"

View the current configuration for a service:

rcctl get nginx

This shows the service name, class, flags, status, timeout, and user. Set the user a daemon runs as:

rcctl set postgresql user _postgresql

Understanding rc.conf.local

On OpenBSD, /etc/rc.conf ships with the base system and should not be edited. All customizations go in /etc/rc.conf.local. The rcctl command manages this file for you. The format uses the daemon name followed by _flags:

nginx_flags=
postgresql_flags=-D /var/postgresql/data
smtpd_flags=
pkg_scripts=nginx postgresql

An empty _flags value means the service is enabled with default settings. The pkg_scripts line controls the startup order for third-party packages.

Quick Reference: FreeBSD vs OpenBSD

Here is a side-by-side comparison of the most common operations:

TaskFreeBSDOpenBSD
Install packagepkg install nginxpkg_add nginx
Remove packagepkg remove nginxpkg_delete nginx
Search packagespkg search termpkg_info -Q term
List installedpkg infopkg_info
Update catalogpkg update(automatic)
Upgrade allpkg upgradepkg_add -u
Remove orphanspkg autoremovepkg_delete -a
Start serviceservice nginx startrcctl start nginx
Stop serviceservice nginx stoprcctl stop nginx
Enable at bootsysrc nginx_enable=YESrcctl enable nginx
Disable at bootsysrc nginx_enable=NOrcctl disable nginx
List enabledservice -ercctl ls on
Config file/etc/rc.conf/etc/rc.conf.local
3rd party scripts/usr/local/etc/rc.d//etc/rc.d/

Conclusion

FreeBSD and OpenBSD handle packages and services differently from Linux but the workflow is straightforward once you know the commands. FreeBSD’s pkg is closer to what apt or dnf users expect, while OpenBSD’s pkg_add/rcctl toolset is more minimal but does the job with less ambiguity. For FreeBSD-specific software guides, check our articles on installing MariaDB on FreeBSD and setting up hostname and static IP on FreeBSD.

Related Articles

FreeBSD How To Install Webmin on FreeBSD 12|FreeBSD 13 Monitoring Linux & FreeBSD Resource Monitoring with bpytop Databases Install and Configure PostgreSQL 17 on FreeBSD 14 FreeBSD How To Configure NFS Server and NFS client on FreeBSD 14

Leave a Comment

Press ESC to close