5.5. Using pkgng for Binary Package Management

pkgng is the next generation replacement for the traditional FreeBSD package management tools, offering many features that make dealing with binary packages faster and easier.

pkgng is not a replacement for port management tools like ports-mgmt/portmaster or ports-mgmt/portupgrade. These tools can be used to install third-party software from both binary packages and the Ports Collection, while pkgng installs only binary packages.

5.5.1. Getting Started with pkgng

FreeBSD 9.1 and later includes a bootstrap utility which can be used to download and install pkgng, along with its manual pages.

To bootstrap the system, run:

# /usr/sbin/pkg

For earlier FreeBSD versions, pkgng must instead be installed from the Ports Collection or as a binary package.

To install the port, run:

# cd /usr/ports/ports-mgmt/pkg
# make
# make install clean

To install the binary package, run:

# pkg_add -r pkg

Once pkgng is installed, the package database must be converted from the traditional format to the new format by running this command:

# pkg2ng

This step is not required for new installations that do not yet have any third-party software installed.


This step is not reversible. Once the package database has been converted to the pkgng format, the traditional pkg_* tools should not be used.


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 third-party software that was not successfully converted will be listed after pkg2ng has finished and these applications must be manually reinstalled.

To ensure that the FreeBSD Ports Collection registers new software with pkgng, and not the traditional packages format, FreeBSD versions earlier than 10.X require this line in /etc/make.conf:


The pkgng package management system uses a package repository for most operations. The default package repository location is defined in /usr/local/etc/pkg.conf or by the PACKAGESITE environment variable, which overrides the configuration file.

Additional pkgng configuration options are described in pkg.conf(5).

Usage information for pkgng is available in pkg(8) or by running pkg without additional arguments.

Each pkgng 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:

# pkg help install
# man pkg-install

The rest of this section demonstrates common binary package management tasks which can be performed using pkgng. Each demonstrated command provides many switches to customize its use. Refer to a command's help or man page for details and more examples.

5.5.2. 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 pkgng is installed, run:

# pkg info pkg

5.5.3. Installing and Removing Packages

To install a binary package use the following command, where packagename is the name of the package to install:

# pkg install packagename

This command uses repository data to determine which version of the software to install and if it has any uninstalled dependencies. For example, to install curl:

# pkg install curl
Updating repository catalogue
/usr/local/tmp/All/curl-7.31.0_1.txz          100% of 1181 kB 1380 kBps 00m01s

/usr/local/tmp/All/ca_root_nss-3.15.1_1.txz   100% of  288 kB 1700 kBps 00m00s

Updating repository catalogue
The following 2 packages will be installed:

        Installing ca_root_nss: 3.15.1_1
        Installing curl: 7.31.0_1

The installation will require 3 MB more space

0 B to be downloaded

Proceed with installing packages [y/N]: y
Checking integrity... done
[1/2] Installing ca_root_nss-3.15.5_1... done
[2/2] Installing curl-7.31.0_1... done
Cleaning up cache files...Done

The new package and any additional packages that were installed as dependencies can be seen in the installed packages list:

# pkg info
ca_root_nss-3.15.5_1	The root certificate bundle from the Mozilla Project
curl-7.31.0_1	Non-interactive tool to get files from FTP, GOPHER, HTTP(S) servers
pkg-1.1.4_6	New generation package manager

Packages that are no longer needed can be removed with pkg delete. For example:

# pkg delete curl
The following packages will be deleted:


The deletion will free 3 MB

Proceed with deleting packages [y/N]: y
[1/1] Deleting curl-7.31.0_1... done

5.5.4. Upgrading Installed Packages

Packages that are outdated can be found with pkg version. If a local ports tree does not exist, pkg-version(8) will use the remote repository catalogue. Otherwise, the local ports tree will be used to identify package versions.

Installed packages can be upgraded to their latest versions by typing pkg upgrade. This command will compare the installed versions with those available in the repository catalogue. When finished, it will list the applications that have newer versions. Type y to proceed with the upgrade or n to cancel the upgrade.

5.5.5. Auditing Installed Packages

Occasionally, software vulnerabilities may be discovered in third-party applications. To address this, pkgng includes a built-in auditing mechanism. To determine if there are any known vulnerabilities for the software installed on the system, run:

# pkg audit -F

5.5.6. 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:

# pkg autoremove
Packages to be autoremoved:

The autoremoval will free 723 kB

Proceed with autoremoval of packages [y/N]: y
Deinstalling ca_root_nss-3.15.1_1... done

5.5.7. Backing Up the Package Database

Unlike the traditional package management system, pkgng includes its own package database backup mechanism. To manually back up the contents of the package database, run the following command, replacing pkgng.db with a suitable file name:

# pkg backup -d pkgng.db

Additionally, pkgng includes a periodic(8) script to automatically perform a daily back up of the package database. This functionality is enabled if daily_backup_pkgng_enable is set to YES in periodic.conf(5).


To disable the periodic script from backing up the package database, set daily_backup_pkgdb_ enable to NO in periodic.conf(5).

To restore the contents of a previous package database backup, run:

# pkg backup -r /path/to/pkgng.db

5.5.8. Removing Stale Packages

By default, pkgng stores binary packages in a cache directory defined by PKG_CACHEDIR in pkg.conf(5). When upgrading packages with pkg upgrade, old versions of the upgraded packages are not automatically removed.

To remove these outdated binary packages, run:

# pkg clean

5.5.9. Modifying Package Metadata

Software within the FreeBSD Ports Collection can undergo major version number changes. To address this, pkgng has a built-in command to update package origins. This can be useful, for example, if lang/php5 is renamed to lang/php53 so that lang/php5 can now represent version 5.4.

To change the package origin for the above example, run:

# pkg set -o lang/php5:lang/php53

As another example, to update lang/ruby18 to lang/ruby19, run:

# pkg set -o lang/ruby18:lang/ruby19

As a final example, to change the origin of the libglut shared libraries from graphics/libglut to graphics/freeglut, run:

# pkg set -o graphics/libglut:graphics/freeglut


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:

# pkg install -Rf graphics/freeglut

All FreeBSD documents are available for download at http://ftp.FreeBSD.org/pub/FreeBSD/doc/

Questions that are not answered by the documentation may be sent to <freebsd-questions@FreeBSD.org>.
Send questions about this document to <freebsd-doc@FreeBSD.org>.