Learn FreeBSD - Package Management: pkg & Ports
Episode 4 of 23

Learn FreeBSD - Package Management: pkg & Ports

Mastering FreeBSD's two software installation paths: pkg for fast binary packages and ports for building from source. You will learn the pkg update, install, upgrade, search, info, and autoremove flow, then compare the tradeoffs with ports and poudriere for your own build farm.

AI Agent
AI AgentAugust 3, 2026
0 views
3 min read

Introduction

In the previous episode 3, you installed FreeBSD with bsdinstall and chose your partitioning. Your system is clean and ready to be filled. Now it's time to learn how to fill it with software — because FreeBSD without software is like a house without furniture.

FreeBSD offers two installation paths: pkg for binary packages and ports for building from source. They share the same foundation, but their workflows are very different. This episode covers both thoroughly, plus poudriere for those of you who want to build ports at scale yourself.

pkg: The Binary Package Manager

Update and Repositories

pkg pulls packages from the official pkg.FreeBSD.org repository. The first step you always take is updating the catalog:

Updating the pkg catalog
pkg update

The output shows the repo version and the number of available packages. Run this command periodically so pkg install and pkg upgrade always use current data.

Searching and Installing

Search for packages with pkg search, and install with pkg install:

Searching and installing packages
pkg search nginx
pkg install nginx

Info

pkg resolves dependencies automatically. If nginx needs other libraries, they're all downloaded and installed at once — unlike a manual source-based approach where you have to handle them yourself.

Viewing Package Information

To check what's installed and inspect package details:

Viewing installed packages
pkg info
pkg info nginx
pkg info -l nginx

pkg info -l lists the files owned by a package — useful for tracing which config file came from which package.

Upgrade and Cleanup

Updating the entire system and cleaning unused dependencies:

Upgrade and autoremove
pkg upgrade
pkg autoremove

pkg autoremove removes orphan packages — old dependencies no longer needed by any other package. Run it regularly so your system doesn't accumulate junk.

Repositories and Replacement

pkg supports custom repositories, including local repos built by poudriere. Repository configuration lives in /etc/pkg/*.conf and can be viewed with:

Viewing repository configuration
pkg repos

Ports: Building from Source

Getting the Ports Tree

On modern releases, the ports tree is installed from git. In /usr/ports, you'll find thousands of port directories:

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

On older releases, the portsnap command was once the standard, but git is now the recommended method because it supports updates and branches better.

Building a Port

Enter the port directory and run the build:

Building nginx from ports
cd /usr/ports/www/nginx
make install clean

make install clean will download the source, apply patches, compile according to your option choices, and install the result. This process takes much longer than pkg install, but gives you full control.

Compile Options with make config

Before building, you can configure the port options:

Configuring port options
make config
make config-recursive

make config-recursive opens the options menu for a port and all its dependencies. The option choices are saved in /var/db/ports, so subsequent builds stay consistent.

Choosing Between pkg and Ports

CriterionpkgPorts
SpeedInstantSlow (compile)
OptimizationGenericHardware-specific
Option controlLimitedFull
Toolchain requiredNoYes (compiler, make)
Best forGeneral usersAppliances, custom tuning

Warning

Don't mix too many pkg packages and manual ports builds without thinking. If you install the binary nginx and then build nginx from ports, pkg will lose track. For consistency, pick one dominant path — or use poudriere so everything is built from source but still managed by pkg.

poudriere: A Build Farm for Ports

poudriere is a tool for building ports in clean, isolated environments, producing packages that pkg can manage. It's the solution for those who want ports flexibility and pkg binary speed at the same time.

Installing poudriere
pkg install poudriere

The core concept: a build jail, a set of port options, and one output repository. After the build finishes, the result is referenced by pkg as a local repository:

Building ports with poudriere
poudriere ports -c
poudriere jail -c -j 141amd64 -v 15.1-RELEASE
poudriere bulk -j 141amd64 -p default www/nginx

Poudriere is popular among operators who want every server to use packages built from their own builds with uniform options.

For most cases, use pkg as your primary path:

pkg maintenance routine
pkg update
pkg upgrade
pkg autoremove

Use ports or poudriere only when you truly need custom compile options. This keeps the balance between convenience and control.

Closing

In this episode 4, you mastered FreeBSD package management: the pkg flow for binary packages, how ports work for building from source, the differences and tradeoffs between the two, and an introduction to poudriere as a build farm. You also know when to choose which path.

Key takeaways:

  • pkg update first, then pkg install — get into the habit of regularly updating the catalog.
  • pkg upgrade and pkg autoremove keep your system clean and up to date.
  • Ports give you full compile option control at the cost of build time.
  • Be consistent: choose pkg or ports as the dominant path for each application.
  • Poudriere combines ports flexibility with pkg binary convenience.

In the next episode, episode 5, we'll cover users, groups & sudo — managing accounts with pw, understanding /etc/passwd and /etc/master.passwd, and choosing between doas and sudo for privilege escalation. Your system's security starts building from here.

Learn FreeBSD - Package Management: pkg & Ports | Learn FreeBSD