Learn the correct procedure for upgrading and auditing installed packages using the built-in pkg interface in FreeBSD.
Packages are applications, that has been precompiled with a default set of options. The packages are tested to work with the current version FreeBSD and the current packages in the repository. The advantage of packages over ports, which has to be compiled, are the simplification of installing. Updating of packages are done with the built-in pkg interface.
# man pkg
Determine the version and patch level of FreeBSD.
Confirm, that you are running the current version and patch level of FreeBSD. The built-in freebsd-version utility can determine the installed, running and userland version and patch level of FreeBSD. These should all match, but it is not uncommon, that userland is different.
# freebsd-version -k -r -u
If the version and patch level of FreeBSD is not up to current, you should upgrade the FreeBSD base system before upgrading packages. Read more about this in How to upgrade to new minor and major releases of FreeBSD..
Backup, upgrade and audit packages.
You might want to backup the current local package database. If the update proces should fail and the package datase became corrupted, then you will be able to restore it. FreeBSD also keeps its own rotated backups via the periodic runs.
# pkg backup -d pkg-backup.db
Update the packages in the FreeBSD repository catalogue.
# pkg update -f
Update the installed packages.
# pkg upgrade
You might want to audit the installed packages against known vulnerabilities.
# pkg audit -F
If major OS version upgrade is detected.
# pkg update -f pkg: Warning: Major OS version upgrade detected. Running "pkg bootstrap -f" recommended pkg: Repository FreeBSD has a wrong packagesite, need to re-create database
The current pkg interface must be changed to match the new version of FreeBSD. This is done by bootstrapping the pkg interface, which will then automatically download and reinstall – all – applications, when upgrading is started.
# pkg bootstrap -f # pkg update -f # pkg upgrade
If upgrading failed or applications no longer work.
I have experienced, that larger desktop computers can break after an upgrade of packages. You should read into error messages on the console and in the logs and try to pin point the actual cause of the problem and look to solve that. The members of The FreeBSD Forums are very kind and competent.
However it is also my experience, that some of the error messages, that are produced, can lead to many forum discussions with more or less helpful solutions. An example is the following failed upgrade, that had an error message about installing files into the same place.
[4/285] Installing librsvg2-rust-2.50.2… pkg: librsvg2-rust-2.50.2 conflicts with librsvg2-2.40.21 (installs files into the same place). Problematic file: /usr/local/bin/rsvg-convert
This problem, as well as other related problems, was solved by issuing a rebuild of all installed packages with the static version of pkg, which is known from upgrading the base system. The reason, that pkg-static is used instead of pkg is, that pkg-static uses static linked libraries, while pkg depends on dynamically linked libraries, which might break during the rebuild.
# pkg-static install -f pkg # pkg-static upgrade -f
If you get segmentation fault from Xorg and GNOME.
If you updated and even reinstalled all applications, but still gets segmentation fault from Xorg and GNOME, then the reason might be found in a graphics adapter related issue. Unfortunately, neither Xorg nor GNOME are unable to produce a log entry, that is of any help here. However, through trial and error, I have experienced, that this is often a result of major developments in the Direct Rendering Manager (DRM) module for Intel and AMD chips. Go through the list of installed packages and remove stale DRM modules as necessary. These are often shown with a question mark (?). Then install the current DRM module and reboot.
# pkg version | more # pkg delete ... # pkg install drm-kmod # reboot
You might want to remove dependencies, that are no longer required by other packages. This kind of packages are also known as leaf dependencies. The pkg interface will list leaf dependencies before removing them.
# pkg autoremove
You might want to clean or delete the local cache of fetched remote packages. This is relevant, if you have limited storage space.
# pkg clean
If this upgrade was performed on a server or other critical production system, then a reboot and test is recommended.
If upgrading was succesful.
The packages on your FreeBSD system is now upgraded, audited and tested.
More about updating FreeBSD.
This page was last updated 2023-04-11.