Tutorial 03 · FreeBSD

Packages vs ports: pkg and ports

Install prebuilt software with pkg, or build it yourself from the ports tree when you need custom options.

Last updated

FreeBSD offers third-party software two ways: binary packages managed by pkg, and the ports tree, which builds the same software from source. Packages are built from ports, so they're the same software; the difference is convenience versus control.

1Everyday pkg commands

pkg search htop          # find software
pkg install htop         # install
pkg info                 # list installed packages
pkg info -l htop         # files installed by a package
pkg which /usr/local/bin/htop
pkg upgrade              # upgrade everything
pkg delete htop          # remove
pkg autoremove           # remove unneeded dependencies
pkg audit -F             # check for known vulnerabilities

2Quarterly or latest

Packages come from a branch: quarterly (the default on releases, with security fixes only between quarters) or latest (updated continuously). To switch, override the repository in /usr/local/etc/pkg/repos/ rather than editing the file under /etc. Check pkg -vv for the repository name your system uses and match it in the override.

pkg -vv | grep -A3 -i url
mkdir -p /usr/local/etc/pkg/repos
# then create an override file there as described in the Handbook, and run:
pkg update -f
pkg upgrade

3Get the ports tree with git

portsnap has been removed; the ports tree is now fetched with git. A shallow clone saves space. Use the quarterly branch (named like 2026Q4) to match quarterly packages, or main to match latest.

pkg install git
git clone --depth 1 https://git.FreeBSD.org/ports.git /usr/ports
# or a quarterly branch:
git clone --depth 1 -b 2026Q4 https://git.FreeBSD.org/ports.git /usr/ports

# update later
git -C /usr/ports pull

4Build a port

cd /usr/ports/sysutils/htop
make config           # choose build options
make install clean

Built ports are registered with pkg, so pkg info, pkg delete and pkg audit still work.

5Which should I use?

Use packages by default. Use ports when you need a non-default option. Mixing the two works but can cause dependency conflicts when pkg upgrades something you built by hand. If you need custom options across many packages, build your own repository with poudriere and point pkg at it.

pkg lock htop       # stop pkg upgrading a locally built package
pkg unlock htop

← All FreeBSD tutorials