Skip to content

Lesson 2 of 9 · 26m

pkg and Ports Without Chaos

Use binary packages by default, build from ports when options matter, and prevent mixed-package drift from becoming an outage.

The ports tree is one of FreeBSD's oldest strengths and one of the easiest ways to make a mess. Binary packages are not inferior builds; they are prebuilt outputs of the ports system with a consistent dependency graph. Ports are for cases where compile-time options, patches, or licensing constraints genuinely matter. A senior operator chooses deliberately, not ideologically.

Use pkg for normal infrastructure

Most hosts should install binary packages:

pkg update
pkg install nginx rsync smartmontools
pkg info nginx
pkg audit

pkg audit is not optional decoration. It checks installed packages against the FreeBSD VuXML vulnerability database. Make it part of patching review, and treat vulnerable packages pinned by obsolete dependencies as architecture problems rather than scanner noise.

Understand quarterly versus latest

FreeBSD package repositories commonly expose quarterly and latest branches. Quarterly is slower-moving and attractive for stable hosts; latest tracks current port versions more closely. The active repository is configured in /usr/local/etc/pkg/repos/FreeBSD.conf or inherited from /etc/pkg/FreeBSD.conf depending on the installation:

FreeBSD: {
  url: "pkg+https://pkg.FreeBSD.org/${ABI}/quarterly",
  mirror_type: "srv",
  enabled: yes
}

Do not casually mix branches across machines that are supposed to be peers. Version drift between a load-balanced pair creates debugging theater where both nodes are 'the same host' until one behaves differently.

Ports are a build system, not a downloader

The ports tree lives in /usr/ports and encodes build instructions, dependencies, patches, and compile-time options:

portsnap fetch update   # legacy systems; newer installs often use git
cd /usr/ports/www/nginx
make config
make install clean

make config opens options such as optional modules, TLS backends, or database variants. Those choices affect dependencies. A package built with one option set is not interchangeable with the default binary package merely because the name matches.

Do not mix pkg and custom ports casually

The practical failure mode is partial replacement: a custom-built library from ports satisfies the same pkg-origin as a binary dependency. The next pkg upgrade can replace or remove pieces underneath your custom build, leaving linked binaries broken. If you need custom builds, consider Poudriere. It builds clean, reproducible package sets in jails:

pkg install poudriere
poudriere jail -c -j 14_2_amd64 -v 14.2-RELEASE
poudriere ports -c -p local
poudriere bulk -j 14_2_amd64 -p local www/nginx

This turns custom compilation into a package repository rather than a snowflake host.

Locking and provenance matter

pkg lock can hold a package version when you intentionally pin it:

pkg lock nginx
pkg lock -l

A lock is a risk acceptance, not a force field. Write down why it exists, who owns removing it, and which vulnerability feeds must be watched. Years later, forgotten locks become unpatched production archaeology.

Field notes

  • Prefer binary packages unless a compile-time option or patch is truly required.
  • pkg audit should run after every repository update, not only during security incidents.
  • Do not edit /usr/local package files in place; use sample files, .conf includes, or local overrides as documented.
  • Poudriere is the correct boundary between 'we need custom ports' and 'production depends on reproducible packages'.

Was this lesson helpful?

Sign in to rate