Learn NetBSD - Package Management: pkgsrc & pkg_add
Episode 4 of 23

Learn NetBSD - Package Management: pkgsrc & pkg_add

Mastering software management on NetBSD: building packages from source with pkgsrc, installing binary packages with pkg_add, and managing packages with pkg_info, pkg_admin, and pkg_chk.

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

Introduction

In episode 3 we successfully installed NetBSD and booted your first system. That system is still "empty" — it only contains the base system. Now it's time to fill it with software: in this episode we'll master NetBSD package management with pkgsrc and pkg_add — the two main paths for installing software outside the base system.

This is one of NetBSD's biggest differences from Linux. On Linux, you're used to a single package manager that unifies the system and its software. On NetBSD, use pkg_add for binary packages and pkgsrc for building from source — both run on top of the base system without mixing into it, exactly as we learned in episode 2. Let's start with the concepts.

The pkgsrc Concept: One Framework, Many Systems

pkgsrc is NetBSD's package build framework that also runs on many other systems: Linux, macOS, FreeBSD, Solaris, and others. This is what gives NetBSD a portability power that extends down to the software level. A single pkgsrc source tree contains thousands of packages, each with its own Makefile, dependencies, and build instructions.

Two ways to use pkgsrc:

MethodCommandSpeedWhen to Use
Binary packagepkg_addFast (download ready-made)Official/popular packages
Build from sourcemake install in /usr/pkgsrcSlow (compilation)Package has no binary, or you want custom flags

Both produce packages that are registered in the same pkg_install database — managed with pkg_info, pkg_admin, and pkg_delete.

Installing Binary Packages with pkg_add

If you install from the NetBSD binary repository, packages are already available as .tgz or .tbz. Use pkg_add with the package name:

Installing a binary package
pkg_add -v htop
Example pkg_add -v output
pkg_add: pkgconf>=2.1.0: installing 'pkgconf-2.1.0'
pkg_add: htop-3.3.0: installing 'htop-3.3.0'
pkg_add: 1 package added

Notice that the dependency (pkgconf) is installed automatically. To search for available packages in the repository:

Searching for packages in the repository
pkg_info -Q htop
pkg_info -Q nmap
Example search results
htop-3.3.0: Interactive process viewer
nmap-7.95: Network exploration tool and security scanner

Info

The official NetBSD binary repository is organized per release and per architecture, e.g. ftp.netbsd.org/pub/pkgsrc/packages/NetBSD/amd64/11.0/. Make sure the PKG_PATH variable points to the repository matching your version and architecture.

Building from Source with pkgsrc

This is the most "NetBSD" path: building a package from source. First, get the pkgsrc source tree. The modern way is via pkgsrc-bootstrap with git:

Getting the pkgsrc source tree
cd /usr
git clone -b pkgsrc-2026Q2 --depth 1 \
    https://github.com/NetBSD/pkgsrc.git pkgsrc

Then to build a package, move to the package directory and run make:

Building a package from source
cd /usr/pkgsrc/sysutils/htop
make install clean
Example build process
=> Checksum OK for htop-3.3.0.tar.gz.
=> Building htop-3.3.0
=> Installing dependencies: ncurses>=6.0
...
=> Installing htop-3.3.0

Building from source takes time, but gives you full control: you can set build options, apply patches, and ensure the binary is optimized for your machine. It's the same philosophy as build.sh in episode 10 — NetBSD emphasizes transparency.

After Building: You Can Create Your Own Binary Package

The build result can be wrapped into a binary package so it can be installed on other machines:

Creating a binary package from a build
make package
Example output
=> Creating binary package /usr/pkgsrc/packages/All/htop-3.3.0.tgz

That binary package can then be moved to another machine and installed with pkg_add. This is a common workflow for deploying software to many identical NetBSD servers.

Managing Packages: pkg_info, pkg_delete, pkg_admin

Listing Installed Packages

Listing all installed packages
pkg_info
Example output
htop-3.3.0                     Interactive process viewer
pkgconf-2.1.0                  Package compiler and linker metadata toolkit

To see the details of a single package — including installed files and dependencies:

Details of a package
pkg_info -v htop
pkg_info -f htop

Removing Packages

Removing a package and unused dependencies
pkg_delete htop
pkg_delete -R htop

The -R option removes the package along with its dependencies that aren't used by other packages.

pkg_admin: Auditing and Verifying the Database

pkg_admin is the package database administration tool. It's most often used to check package integrity:

Checking for broken packages
pkg_admin check
Example output
Checking pkgconf-2.1.0 ...
Checking htop-3.3.0 ...
All packages installed correctly

pkg_admin can also display dependencies (with pkg_admin deptree) and check for missing files (pkg_admin lsall) — useful during system audits.

Updating Packages: pkg_add -u and pkg_chk

Updating packages on NetBSD can be done in two ways:

  1. pkg_add -u — updates packages to the latest versions available in the repository:
Updating all packages from the binary repository
pkg_add -u
  1. pkg_chk (itself a pkgsrc package) — matches installed packages against the versions available in the source tree, then builds the ones that are behind:
Install pkg_chk, then check for outdated packages
cd /usr/pkgsrc/pkgtools/pkg_chk
make install
pkg_chk -u

pkg_chk -u rebuilds every package whose version is older than what's available in the source tree — the most "NetBSD" flow for keeping a system fresh.

Closing

In this episode 4, you've mastered NetBSD's two package management paths: pkgsrc for building from source with make install in /usr/pkgsrc, and pkg_add for installing ready-to-use binary packages. You also learned to manage packages with pkg_info, pkg_delete, pkg_admin, and to update them with pkg_add -u and pkg_chk.

Key takeaways:

  • pkgsrc is a multi-platform build framework; packages install into /usr/pkg, separate from the base system.
  • pkg_add for fast binaries, make install in the source tree for full control.
  • Manage with pkg_info (list), pkg_delete (remove), pkg_admin (audit).
  • Update automatically with pkg_add -u or pkg_chk -u.
  • Build results can be wrapped into a binary package with make package for distribution.

In the next episode, episode 5, we'll manage the system's inhabitants: users, groups, and privileges — creating accounts with useradd, managing groups in /etc/group, and limiting root access with su, doas, and sudo. See you in episode 5!

Learn NetBSD - Package Management: pkgsrc & pkg_add | Learn NetBSD