For the complete documentation index, see llms.txt. This page is also available as Markdown.

8.3 Managing Binary Packages with pkg

FreeBSD's current binary package manager is pkg (formerly pkgng), named after the English word "Package," which is an abbreviation for software package.

Installing the pkg Package Manager

Tip

To avoid backward compatibility issues, the pkg(8) tool is not pre-installed in the base system.

The base system does not include pkg by default; you need to download and install pkg first:

# pkg # Type pkg and press Enter
The package management tool is not yet installed on your system. # pkg is not yet installed
Do you want to fetch and install it now? [y/N]: y # Type y and press Enter to confirm installation
Bootstrapping pkg from pkg+https://pkg.FreeBSD.org/FreeBSD:14:amd64/quarterly, please wait... # Note here, the default is the quarterly branch repository
Verifying signature with trusted certificate pkg.freebsd.org.2013102301... done
Installing pkg-1.21.3...
Extracting pkg-1.21.3: 100%
pkg: not enough arguments # This error indicates missing arguments, but it's just for installing pkg itself and can be ignored
Usage: pkg [-v] [-d] [-l] [-N] [-j <jail name or id>|-c <chroot path>|-r <rootdir>] [-C <configuration file>] [-R <repo config dir>] [-o var=value] [-4|-6] <command> [<args>]

For more information on available commands and options see 'pkg help'.

Tip

If it stays at Bootstrapping pkg from ……, please wait... for a long time, press Ctrl + C to interrupt the process, switch to a domestic repository, and try again.

Tip

If you see the message 00206176BC680000:error:0A000086:SSL routines:tls_post_process_server_certificate:certificate verify failed:/usr/src/crypto/openssl/ssl/statem/statem_clnt.c:1890: (SSL certificate verification failed), please calibrate the system time first.

Discussion Question

In the context of widespread SSL usage, any network issue always requires checking whether the local system time is correct. Users often overlook this (sometimes it is even caused by a damaged encryption module in the CPU), and in most cases, the error messages are extremely unclear. Please think about how to solve this problem.

Installing Software with pkg

Tip

If you need to check the specific status of a software package in FreeBSD, you can search for "freebsd ports package_name" using a search engine, or look it up directly on FreshPorts.

Using the installation of Chromium as an example:

"Insufficient privileges to install packages" means "insufficient privileges, unable to install packages."

Try again:

Discussion Question

It can be seen that pkg supports neither parallel downloads nor parallel installations. Read the source code, try to solve this problem, and submit a PR.

You may encounter this situation:

"pkg: No packages available to install matching 'chromium' have been found in the repositories" means "pkg: No packages matching chromium were found in the repositories for installation."

If the preceding output showed "FreeBSD repository update completed. 36804 packages processed." (FreeBSD repository update completed. 36804 packages processed), it means the current software repository is available; it just cannot find the chromium package.

This is a manifestation of the "atomic update" deficiency described below.

Additionally, even if the system has i18n configured, pkg's output remains in English.

Discussion Question

The FreeBSD base system does not have gettext, so there are no plans to do this. If a usable libintl suite becomes available in pkg in the future, this may be reconsidered.

Read the pkg source code, locate the source of the problem, try to solve it, and submit a PR to enable i18n support in pkg.

Updating Software with pkg

If the error appears: You must upgrade the ports-mgmt/pkg port first (You must update pkg itself first).

Solution (prefer using pkg's own upgrade, or compile via Ports):

Or:

Viewing All Installed Software

Uninstalling Software

pkg delete automatically adds packages with unsatisfied dependencies to the deletion list by default and will not break dependency relationships; it only skips dependency checks when the -f parameter is used. If you need to clean up "leaf" packages that are no longer depended on by other packages, you can install pkg_rmleaves or use the built-in command pkg autoremove to remove automatically installed packages that no longer have dependents.

Or

How to Uninstall All Self-Installed Third-Party Software?

References

Listing Files Installed by a pkg Package

Tip

The download path for pkg is /var/cache/pkg/.

Note

You can only list files of installed software packages; this command cannot be used for packages that are not installed.

Finding Missing .so Files (Applicable to Linux Compatibility Layer)

Warning

This section only addresses the issue of missing .so files in the Linux compatibility layer. If you encounter such issues on FreeBSD, you should first update the system, then update the software repositories and software.

Installing pkg-provides

Or:

Configuring pkg-provides

  • View configuration instructions:

Directory structure:

  • Edit the /usr/local/etc/pkg.conf file, find the empty line, and write:

  • Run pkg plugins:

  • Refresh the database:

Example: Finding libxcb-icccm.so.4

Troubleshooting and Unfinished Business

Unable to Find Packages Mentioned in This Book in pkg

When using pkg to install software packages explicitly mentioned in the textbook and receiving a prompt that they do not exist, the cause can generally be attributed to the following two situations:

  • Situation 1: The Port does not actually exist in Ports. Possible reasons include errors in the textbook, the Port has been removed from the Ports collection, or it has been renamed.

  • Situation 2: The Port does exist in Ports, but FreeBSD's pkg packages are built periodically (synchronized with Ports' own updates), so there is often a temporary lack of corresponding pkg binary packages.

For specific reasons, it is recommended to check https://www.freshports.org/, which displays the dependency status and pkg package build status of software packages.

This book generally also lists the Ports installation method. For example, to look up Port x11/budgie, the procedure is as follows: directly visit https://www.freshports.org/x11/budgie/.

If the Port exists in Ports but there is temporarily no pkg package, waiting 7–14 days is usually sufficient (the system automatically reports build failures to the maintainer). If you need to install and use it immediately, please use Ports.

ld-elf.so.1: Shared object "libmd.so.6" not found, required by "pkg"

This problem is usually caused by the software repository not being synchronized with changes to the base system ABI in a timely manner.

For general RELEASE, updating the system is sufficient. For CURRENT/STABLE systems, recompiling pkg is sufficient.

RELEASE

First switch to the latest repository, then reinstall pkg using the pkg package from the repository:

If ineffective, then:

CURRENT/STABLE

pw: user 'package' disappeared during update

Problem example:

The cause is that the user database is out of sync.

Update the password database according to /etc/master.passwd:

Shared object "x.so.x" not found, required by "xxx"

This problem usually occurs because the ABI has been broken; updating will resolve it.

Install bsdadminscripts2 using pkg:

Or install bsdadminscripts2 using Ports:

Check whether the dynamic library dependencies of installed software packages are complete:

Recompile each package in the above list using Ports (RELEASE can update directly with pkg).

Appendix: Extended Usage and References for bsdadminscripts2

  • lonkamikaze. BSD Administration Scripts II[EB/OL]. [2026-03-25]. https://github.com/lonkamikaze/bsda2. Provides FreeBSD system administration auxiliary toolset, including package integrity check and other functions.

If PkgBase is used, bsdadminscripts2 can check system integrity and find which system files have been tampered with.

Verify the integrity and consistency of installed software packages:

  • bsdadminscripts2 can also find outdated software on the current system:

Newer FreeBSD version for package pkg

Problem example:

This usually occurs on systems that have lost security support or on CURRENT/STABLE branch systems. It does not affect usage; just type y.

To resolve this at the root, you need to uninstall pkg and install ports-mgmt/pkg from Ports; or update the entire system from source code.

If you only need to suppress this prompt, simply write IGNORE_OSVERSION=yes to the /etc/make.conf file as instructed (create the file if it does not exist).

pkg: An error occurred while fetching package: No error

Execute certctl rehash with root privileges to refresh certificates.

See: pkg(8): "An error occurred while fetching package: No error"[EB/OL]. [2026-03-26]. https://forums.freebsd.org/threads/pkg-8-an-error-occured-while-fetching-package-no-error.96761/.

Appendix: Analysis of the Difficulties and Current Status of FreeBSD Package Atomic Updates

FreeBSD mirror sites' software repositories (whether official or unofficial) exhibit the following typical phenomena:

  • Once a Port is updated, the pkg binary package derived from that Port is immediately removed from the software repository until a new pkg package is built, rather than keeping the old version of the package;

  • As soon as a new build begins, the old version package is immediately deleted from the pkg software repository until a new version of the pkg package is built.

A feasible solution is to lock software packages at a fixed version stage (such as the quarterly branch), temporarily not updating, and directly rotating versions.

The problem is that Port updates are irregular, and complex dependency relationships may trigger chain issues. Those with the ability can try to propose new perspectives and suggestions, and provide feedback below or on the FreeBSD Forum.

Discussion Question

Try: Help the FreeBSD Project implement atomic updates for pkg binary packages?

Exercises

  1. Read the pkg source code, locate the implementation of parallel downloads and installations, try to add parallel download functionality, and verify whether it significantly improves installation speed.

  2. Select the atomic update issue of pkg, design an experimental plan, reproduce the problem, and propose a feasible solution.

  3. Add i18n support to pkg.

Last updated