pkgng is an improved replacement for the traditional FreeBSD package management tools, offering many features that make dealing with binary packages faster and easier. The first release of pkgng was in August, 2012.
pkgng is not a replacement for port management tools like ports-mgmt/portmaster or ports-mgmt/portupgrade. While ports-mgmt/portmaster and ports-mgmt/portupgrade can install third-party software from both binary packages and the Ports Collection, pkgng installs only binary packages.
FreeBSD 9.1 and later includes a "bootstrap" utility for pkgng. The bootstrap utility will download and install pkgng.
To bootstrap the system, run:
# /usr/sbin/pkg
For earlier FreeBSD versions, pkgng must be installed from the Ports Collection, or as a binary package.
To install the pkgng port, run:
# cd /usr/ports/ports-mgmt/pkg # make # make install clean
To install the binary package, run:
# pkg_add -r pkg
Note: The pkgng package management utility is not supported on FreeBSD 7.X or FreeBSD 8.0.
Existing FreeBSD installations require conversion of the pkg_install package database to the new format. To convert the package database, run:
# pkg2ng
This step is not required for new installations that do not have third-party software installed.
Important: This step is not reversible. Once the package database has been converted to the pkgng format, the pkg_install tools should not be used.
Note: 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. These must be fixed by hand.
To ensure the FreeBSD Ports Collection registers new software with pkgng, and not pkg_install, FreeBSD versions earlier than 10.X require this line in /etc/make.conf:
WITH_PKGNG= yes
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 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 the pkg(8) manual page, 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:
# pkg help install
# man pkg-install
Information about the packages installed on a system can be viewed by running pkg info. Similar to pkg_info(1), the package version and description for all packages will be listed.
Information about a specific package is available by running:
# pkg info packagename
For example, to see which version of pkgng is installed on the system, run:
# pkg info pkg pkg-1.0.2 New generation package manager
In general, most FreeBSD users will install binary packages by running:
# pkg install packagename
pkg install uses repository data, as mentioned in Section 5.5.2. Conversely, pkg-add(8) does not use repository data, nor does it use the defined PACKAGESITE, so dependencies may not be properly tracked, and missing dependencies will not be fetched from a remote source. This section covers usage of pkg install. For information on usage of pkg add, see pkg-add(8).
Additional binary packages can be installed with pkg install. For example, to install curl:
# pkg install curl Updating repository catalogue Repository catalogue is up-to-date, no need to fetch fresh copy The following packages will be installed: Installing ca_root_nss: 3.13.5 Installing curl: 7.24.0 The installation will require 4 MB more space 1 MB to be downloaded Proceed with installing packages [y/N]: y ca_root_nss-3.13.5.txz 100% 255KB 255.1KB/s 255.1KB/s 00:00 curl-7.24.0.txz 100% 1108KB 1.1MB/s 1.1MB/s 00:00 Checking integrity... done Installing ca_root_nss-3.13.5... done Installing curl-7.24.0... 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.13.5 The root certificate bundle from the Mozilla Project curl-7.24.0 Non-interactive tool to get files from FTP, GOPHER, HTTP(S) servers pkg-1.0.2 New generation package manager
Packages that are no longer needed can be removed with pkg delete. For example, if it turns out that curl is not needed after all:
# pkg delete curl The following packages will be deleted: curl-7.24.0_1 The deletion will free 3 MB Proceed with deleting packages [y/N]: y Deleting curl-7.24.0_1... done
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.
Packages can be upgraded to newer versions with pkgng. Suppose a new version of curl has been released. The local package can be upgraded to the new version:
# pkg upgrade Updating repository catalogue repo.txz 100% 297KB 296.5KB/s 296.5KB/s 00:00 The following packages will be upgraded: Upgrading curl: 7.24.0 -> 7.24.0_1 1 MB to be downloaded Proceed with upgrading packages [y/N]: y curl-7.24.0_1.txz 100% 1108KB 1.1MB/s 1.1MB/s 00:00 Checking integrity... done Upgrading curl from 7.24.0 to 7.24.0_1... done
Occasionally, software vulnerabilities may be discovered in software within the Ports Collection. pkgng includes built-in auditing, similar to the ports-mgmt/portaudit package. To audit the software installed on the system, run:
# pkg audit -F
Removing a package may leave behind unnecessary dependencies, like security/ca_root_nss in the example above. Such packages are still installed, but nothing depends on them any more. Unneeded packages that were installed as dependencies can be automatically detected and removed:
# pkg autoremove Packages to be autoremoved: ca_root_nss-3.13.5 The autoremoval will free 723 kB Proceed with autoremoval of packages [y/N]: y Deinstalling ca_root_nss-3.13.5... done
Unlike the traditional package management system, pkgng includes its own package database backup mechanism. To manually back up the package database contents, run:
# pkg backup -d pkgng.db
Note: Replace the file name pkgng.db to a suitable file name.
Additionally, pkgng includes a periodic(8) script to automatically back up the package database daily if daily_backup_pkgng_enable is set to YES in periodic.conf(5).
Tip: To prevent the pkg_install periodic script from also 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
By default, pkgng stores binary packages in a cache directory as 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 the outdated binary packages, run:
# pkg clean
Historically, software within the FreeBSD Ports Collection can undergo major version number changes. Unlike pkg_install, pkgng has a built-in command to update package origins. For example, if lang/php5 was originally at version 5.3, but has been renamed to lang/php53 for the inclusion of version 5.4, pkg_install would require the use of additional software such as ports-mgmt/portmaster to update the package database, reflecting from which port the installation originated.
Unlike the ports-mgmt/portmaster and ports-mgmt/portupgrade ports, the order in which the new and old versions are listed differ. For pkgng, the syntax is:
# pkg set -o category/oldport:category/newport
For example, 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
Note: When changing package origins, in most cases it is important to reinstall packages that are dependent on the package that has had the origin changed. To force a reinstallation of dependent packages, run:
# pkg install -Rf graphics/freeglut