OpenBSD Handbook

    Theme
    • Part I. Install & Configure
      • Introduction
      • Installing OpenBSD
      • The X Window System
      • Networking
      • System Configuration
      • OpenBSD Basics
      • Managing Software: Packages and Ports
    • Part II. Daily Operations
      • Graphical Environments
      • Multimedia
      • Printing
      • Linux Compatibility
      • Windows Compatibility
      • Games
    • Part III. System Administration
      • Virtualization
      • Storage and File Systems
      • Updating and Upgrading
      • Localization
      • The OpenBSD Boot Process
      • Security
    • Part IV. Networking & Daemons
      • Services
        • Database
          • MariaDB
          • PostgreSQL
          • Redis
          • memcached
        • Directory
          • YP (NIS)
          • LDAP
        • File
          • NFS
          • Samba
        • FTP Services
          • ftpd
          • ProFTPD
          • vsftpd
          • Pure-FTPd
          • TFTP
        • Mail
          • smtpd
          • Dovecot
          • Postfix
          • Exim
          • Rspamd
        • Name
          • Unbound
          • NSD
          • BIND
        • Networking
          • OpenBGPD
          • rad
          • DHCP
          • slaacd
        • Web
          • Apache
          • nginx
          • httpd
          • relayd
        • Logging
          • syslogd
        • Monitoring
          • SNMP
        • Remote Access
          • Audit OpenSSH
          • sshd
        • File Synchronization
          • rsync
        • Messaging
          • RabbitMQ
        • Time
          • NTP
      • PF
        • pfctl cheat sheet
        • PF Anchors
        • PF Filter Rules
        • PF Forwarding
        • PF Lists and Macros
        • PF Load Balancing
        • PF Logging
        • PF NAT
        • PF Options
        • PF Policies
        • PF Shortcuts
        • PF Tables
      • Advanced Networking
        • High Availability and State Replication
        • Multi-WAN and Policy-Based Routing
        • VPN and Cryptographic Tunneling
        • Classic and Lightweight Tunnels
        • IPv6 at Scale
        • QoS and Traffic Shaping
        • MPLS and Label Distribution
        • Network Services at Scale
        • Virtualization and Host Networking
        • Large-Scale L2 and L3 Design
        • Telemetry, Logging, and Flow Export
        • Hardening and Operational Safety
        • Reference Architectures
        • Troubleshooting Playbooks
      • Serial Communication
    • Part V. Miscellaneous
      • Virtualization Cheat Sheet
      • OpenBSD Cheatsheet
      • How-to Guides
        • Complete the First 30 Minutes After Installation
        • Check Hardware Compatibility Before Installing
        • Bootstrap Wi-Fi Firmware Without Ethernet
        • Set Up OpenBSD as a Laptop or Workstation
        • Configure Laptop Power Management
        • Run OpenBSD as a Virtual Machine Guest
        • Install OpenBSD on a VPS or Cloud Server
        • Install OpenBSD with Full-Disk Encryption
        • Troubleshoot Web Browsers on OpenBSD
        • Create an Administrator Account with doas and SSH Keys
        • Establish a Conservative Security Baseline
        • Manage OpenBSD with Ansible
        • Recover Access and Reset the Root Password
        • Collect OpenBSD Diagnostic Evidence
        • Configure Secure Remote Access with OpenSSH
        • Set Up WordPress
        • Build Third-Party Software from Ports
        • Use FIDO Security Keys with OpenSSH
        • Build OpenBSD from Source
        • Configure Wi-Fi Roaming and Wired Failover
        • Dual-Boot OpenBSD on a UEFI System
        • Troubleshoot PF, NAT, and Routing
        • Automate OpenBSD Installation with Autoinstall and PXE
        • Route Multiple VLANs with PF
        • Configure a Road-Warrior WireGuard VPN
        • Troubleshoot Package Installation and Update Failures
        • Route IPv6 Networks without NAT
        • Schedule Recurring Maintenance
        • Plan a Docker Workload Migration to OpenBSD
        • Build a Mail Server with OpenSMTPD, Dovecot, and Rspamd
        • Build a Simple Router and Firewall
        • Monitor an OpenBSD System
        • Back Up and Restore an OpenBSD System
        • Configure softraid RAID1
        • Recover an OpenBSD System That Does Not Boot
        • Install Z shell (zsh)
      • OpenBSD for Linux Users
      • OpenBSD for FreeBSD Users
      • OpenBSD for macOS Users
    • OpenBSD FAQ
    • OpenBSD Package Search
      • Synopsis
      • Package and System Boundaries
      • Select the Package Mirror
      • Search for Packages
      • Install Packages
      • Update Packages
      • Remove Packages
      • Record Package State and Repair Interrupted Transactions
      • Reproduce a Package Set
      • Use the Ports Tree Only When Required
      • Build Sets Are Not Packages
      • Read the Primary Documentation

      Managing Software: Packages and Ports

      Synopsis #

      OpenBSD builds signed binary packages from its ports tree. Most systems should install and update third-party software with the pkg_* tools. The ports tree is intended for maintained source builds, custom flavors, local port testing, and package development, and it must match the running OpenBSD branch.

      This chapter covers the package-first workflow and the boundary between packages, ports, firmware, base-system patches, and release upgrades. Build Third-Party Software from Ports provides the complete single-port build procedure. Troubleshoot Package Installation and Update Failures provides a symptom-driven recovery path for source, release, dependency, and interrupted-transaction errors.

      Package and System Boundaries #

      OpenBSD maintenance has distinct layers:

      LayerPrimary toolPurpose
      Base-system erratasyspatchApply signed binary patches to a supported release
      Firmware packagesfw_updateInstall and update firmware required by supported devices
      Third-party packagespkg_add, pkg_delete, pkg_infoInstall and maintain software built from ports
      Release upgradesysupgrade or installer upgradeMove the complete base system to the next release
      Ports treemake, dpbBuild maintained third-party packages from source

      A package update does not update the base system, and syspatch does not update packages. See Update and Upgrade OpenBSD for the coordinated workflow.

      Select the Package Mirror #

      The installer normally writes an official mirror URL to installurl(5) :

      $ cat /etc/installurl
      

      Use an official mirror appropriate to the network. The package tools derive the release and architecture path. Set PKG_PATH only for a deliberate alternate repository or diagnostic case; a stale value can mix incompatible package sources.

      Search for Packages #

      Search package names with pkg_info(1) :

      $ pkg_info -Q rsync
      

      Package names can include branches, flavors, and subpackages. Let pkg_add(1) present valid choices when a short stem is ambiguous rather than copying a versioned filename from another release.

      To locate the package that contains a file, install the pkglocatedb package and update its database through the package’s documented method, then use pkglocate. This optional database describes available packages and should be refreshed after repository changes.

      Install Packages #

      Install a package as root:

      # pkg_add rsync
      

      The package tool verifies signed packages from trusted repositories and records dependencies, files, pkgpaths, and installation messages. Read messages printed during installation and any relevant file under /usr/local/share/doc/pkg-readmes/ before enabling a service or changing login classes.

      Use pkg_info(1) to inspect the result:

      $ pkg_info rsync
        # Display package metadata
      $ pkg_info -L rsync
        # Display installed files
      

      Do not install an arbitrary package URL merely to bypass mirror selection or signature policy.

      Update Packages #

      Update all installed packages after base-system maintenance and during the documented release-upgrade sequence:

      # pkg_add -u
      

      On snapshot systems, package and base snapshots must remain sufficiently synchronized. Read current snapshot guidance before forcing an update across a repository transition.

      The -U option permits dependency updates while installing a new package and can leave a partially updated set. It is primarily useful in deliberate snapshot workflows; it should not replace a normal full pkg_add -u maintenance run.

      Remove Packages #

      Remove a selected package with pkg_delete(1) :

      # pkg_delete rsync
      

      Review reverse dependencies and package messages before removal. Remove no-longer-required automatic dependencies only after previewing the affected set:

      # pkg_delete -an
        # Preview automatic packages that would be removed
      # pkg_delete -a
        # Remove them only after the preview is acceptable
      

      Package removal can retain locally modified configuration. Review reported extra files instead of deleting /etc or /usr/local paths recursively.

      Record Package State and Repair Interrupted Transactions #

      List manually installed package stems for reproducible host records:

      $ pkg_info -mz
      

      The package database normally requires no manual check. After a system failure interrupts pkg_add or pkg_delete, inspect the error and use pkg_check(8) conservatively:

      # pkg_check
      

      pkg_check can perform safe repairs and can request confirmation for more permanent changes. Preserve the first transaction error and back up package metadata before forcing repairs.

      Do not delete partial-* or .libs-* packages blindly. They can represent an interrupted operation or retained shared libraries required by running or installed software. Read the package-tool diagnostics and complete or repair the interrupted transaction.

      Reproduce a Package Set #

      Create a list of manually installed package stems:

      $ pkg_info -mz > installed-package-stems.txt
      

      Review the file before using it on another host. Architecture, release, flavor availability, local packages, and host role can differ. Install a reviewed list with:

      # pkg_add -l installed-package-stems.txt
      

      This reproduces requested package stems, not service configuration, user data, secrets, or exact historic package files.

      Use the Ports Tree Only When Required #

      The ports(7) framework downloads upstream distfiles, applies OpenBSD patches, builds under the ports infrastructure, and creates packages installed by the package tools.

      Use ports when:

      • a supported flavor is required but no matching binary package is published;
      • a local ports patch must be tested;
      • a port is being developed or maintained;
      • a controlled package repository is being built.

      Do not use a ports build merely because source compilation is assumed to be faster or more secure. Local builds create an additional patching, provenance, storage, and reproducibility obligation.

      The ports tree must follow the same release or development branch as the base system. Do not combine release packages, a snapshot base, and an unrelated ports checkout.

      Build Sets Are Not Packages #

      OpenBSD distribution sets such as comp, xbase, and xshare are part of the base system, not packages. If sets were omitted, boot the installed bsd.rd, choose (U)pgrade, and select the missing sets for the same release. Do not extract selected libraries or binaries manually into a running system.

      Read the Primary Documentation #

      The package tools and ports infrastructure evolve. Consult the current manuals for pkg_add(1) , pkg_delete(1) , pkg_info(1) , packages(7) , pkgpath(7) , ports(7) , and bsd.port.mk(5) before scripting package selection or ports builds.

      Report a bug
      • Synopsis
      • Package and System Boundaries
      • Select the Package Mirror
      • Search for Packages
      • Install Packages
      • Update Packages
      • Remove Packages
      • Record Package State and Repair Interrupted Transactions
      • Reproduce a Package Set
      • Use the Ports Tree Only When Required
      • Build Sets Are Not Packages
      • Read the Primary Documentation