PKGng: The new package manager of FreeBSD
So what’s PKGng?
pkg is the new package manager of FreeBSD. Packages in FreeBSD used to be managed using several different commands, some of them with overlapping functionality (
pkg_deinstall). The whole system was functional but inefficient. It was also slow due to the underlying infrastructure. Everyone who has ever used
pkg_info knows what I am talking about. The new system is much faster due in part to the use of an SQLite database.
Some time ago, the task of re-thinking the package manager was taken over by a group FreeBSD developers. Finally, with the upcoming of the 9.1-RELEASE version,
pkg was included in the base system.
pkg provides both a way for managing binary packages (including upgrades) and a library so it should be easy to write frontends for the system. Installation is straightforward:
<code>[root@beastie /usr/home/fernape]# pkg The package management tool is not yet installed on your system. Do you want to fetch and install it now? [y/N]: y Bootstrapping pkg please wait Installing pkg-1.0.11... done If you are upgrading from the old package format, first run: # pkg2ng usage: pkg [-v] [-d] [-j |-c ]  Global options supported: -d Increment debug level -j Execute pkg(1) inside a jail(8) -c Execute pkg(1) inside a chroot(8) -v Display pkg(1) version Commands supported: add Registers a package and installs it on the system audit Reports vulnerable packages autoremove Removes orphan packages backup Backs-up and restores the local package database check Checks for missing dependencies and database consistency clean Cleans old packages from the cache create Creates software package distributions delete Deletes packages from the database and the system fetch Fetches packages from a remote repository help Displays help information info Displays information about installed packages install Installs packages from remote package repositories query Queries information about installed packages register Registers a package into the local database remove Deletes packages from the database and the system repo Creates a package repository catalogue rquery Queries information in repository catalogues search Performs a search of package repository catalogues set Modifies information about packages in the local database shell Opens a debug shell shlib Displays which packages link against a specific shared library stats Displays package database statistics update Updates package repository catalogues updating Displays UPDATING information for a package upgrade Performs upgrades of packaged software distributions version Displays the versions of installed packages which Displays which package installed a specific file For more information on the different commands see 'pkg help '. </code>
First off, we need to convert the old packages to the new format.
pkg2ng tool performs this task:
<code>[root@beastie /usr/home/fernape]# pkg2ng Creating backup pkg_info(1) database directory in /var/db/pkg.bak. Installing GraphicsMagick-1.1.15_5,1... done Installing ImageMagick-184.108.40.206_1... done Installing ORBit2-2.14.19... done Installing OpenSP-1.5.2_2... done ... ... Conversion has been successfully finished Your old packages database has been moved to: /var/db/pkg.bak. </code>
In FreeBSD, everything is a package. Even if we compile our software using the ports collection, the last stage before install is to create a package for the software. In order to instruct our system to use PKGng as the new package management tool, we have to edit /etc/make.conf and add the following line:
pkg provides a useful query system for obtaining information about packages. With it, you can use certain defined placeholders that will be substituted properly. For instance:
<code>$ pkg query "%n was installed from %o on %t" bash bash was installed from shells/bash on 1369848469 $ pkg query "%n dependency:nt%dn" bash bash dependency: libiconv bash dependency: gettext $ pkg query "%n version %v takes %sh of disk space" firefox firefox version 20.0,1 takes 55 MB of disk space </code>
For more information, see pkg’s man page.
pkg is the present and the future of FreeBSD packages. Due to its modular design (most of the functionality is encapsulated in a library) it should be easy to write frontends for it (see this and this)
The new system is much faster than the old one and a lot of thought was put on it during development. Try it now!