Using pkgng Package Management
| This page needs an investigation! |
It seems it is out of date.
|Using pkgng 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.
Getting Started with pkgng
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.
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
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.4.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.4.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.4.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: 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.15.1_1... done
5.4.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). Tip:
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.4.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.4.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