Using pkg for Binary Package Management pkg is the next generation replacement for the traditional FreeBSD package management tools, offering many features that make dealing with binary packages faster and easier. For sites wishing to only use prebuilt binary packages from the FreeBSD mirrors, managing packages with pkg can be sufficient.
However, for those sites building from source or using their own repositories, a separate port management tool will be needed. Since pkg only works with binary packages, it is not a replacement for such tools. Those tools can be used to install software from both binary packages and the Ports Collection, while pkg installs only binary packages.
Getting Started with pkg FreeBSD includes a bootstrap utility which can be used to download and install pkg and its manual pages. This utility is designed to work with versions of FreeBSD starting with Not all FreeBSD versions and architectures support this bootstrap process. The current list is at https: For other cases, pkg must instead be installed from the Ports Collection or as a binary package. To bootstrap the system, run: Otherwise, to install the port, run: Once pkg has been installed, the package database must be converted from the traditional format to the new format by running this command: This step is not required for new installations that do not yet have any third-party software installed.
This step is not reversible. The package database conversion may emit errors as the contents are converted to the new version. Generally, these errors can be safely ignored.
However, a list of software that was not successfully converted is shown after pkg2ng finishes. These applications must be manually reinstalled. To ensure that the Ports Collection registers new software with pkg instead of the traditional packages database, FreeBSD versions earlier than Additional pkg configuration options are described in pkg.
Usage information for pkg is available in the pkg 8 manual page or by running pkg without additional arguments. Each pkg command argument is documented in a command-specific manual page. To read the manual page for pkg install, for example, run either of these commands: Each demonstrated command provides many switches to customize its use. Refer to a command's help or man page for details and more examples. Obtaining Information About Installed Packages Information about the packages installed on a system can be viewed by running pkg info which, when run without any switches, will list the package version for either all installed packages or the specified package.
For example, to see which version of pkg is installed, run: Installing and Removing Packages To install a binary package use the following command, where packagename is the name of the package to install: For example, to install curl: Done The new package and any additional packages that were installed as dependencies can be seen in the installed packages list: Upgrading Installed Packages Installed packages can be upgraded to their latest versions by running: Auditing Installed Packages Software vulnerabilities are regularly discovered in third-party applications.
To address this, pkg includes a built-in auditing mechanism. To determine if there are any known vulnerabilities for the software installed on the system, run: Automatically Removing Leaf Dependencies Removing a package may leave behind dependencies which are no longer required. Unneeded packages that were installed as dependencies can be automatically detected and removed using: Restoring the Package Database Unlike the traditional package management system, pkg includes its own package database backup mechanism.
This functionality is enabled by default. If restoring a backup taken by the periodic script, it must be decompressed prior to being restored. Only copies of the latest installed packages are kept. Older versions of pkg kept all previous packages. To remove these outdated binary packages, run: To address this, pkg has a built-in command to update package origins. To change the package origin for the above example, run: When changing package origins, it is important to reinstall packages that are dependent on the package with the modified origin.
To force a reinstallation of dependent packages, run: