5.4. Using Binary Packages

At the present time, FreeBSD is transitioning toward a new method of package management. Users may wish to investigate the benefits of using PKGng to manage third-party software on FreeBSD. This section describes the traditional method for managing binary packages and only applies to those users who have not yet migrated to the pkgng format.

This method of package management uses a package database directory, /var/db/pkg, to track installed software versions and the files installed with each application. Several utilities interact with the database directory and are used to manage binary packages. These commands begin with pkg_. This section provides an overview of the commands which are used to install, delete, and gather information about binary packages. Each command provides many switches to customize its operation. Refer to the listed man pages for more details and further usage examples.

5.4.1. Installing a Package

To install a binary package from a local FreeBSD media or a remote FreeBSD package server, use pkg_add(1). While a FreeBSD media can provide a source of local packages without requiring a network connection, it may not contain the latest versions of binary packages as new versions are always being rebuilt for the FreeBSD package servers. To install from a package server, always include -r (for remote) with pkg_add(1). This automatically determines the correct object format and release, and then fetches and installs the package from a package server without any further user intervention.

# pkg_add -r lsof

In this example, lsof is used without specifying a version number as the version is not included when the remote fetching feature is used. To specify an alternative FreeBSD FTP mirror, specify the mirror in the PACKAGESITE environment variable. pkg_add(1) uses fetch(3) to download files, which uses various environment variables, including FTP_PASSIVE_MODE, FTP_PROXY, and FTP_PASSWORD. You may need to set one or more of these if you are behind a firewall, or need to use an FTP/HTTP proxy. See fetch(3) for the complete list of FTP-related variables.


pkg_add(1) will automatically download the latest version of the application if you are using FreeBSD-CURRENT or FreeBSD-STABLE. If you run a -RELEASE version, it instead installs the version of the package that was built with that release. It is possible to change this behavior by overriding PACKAGESITE. For example, on a FreeBSD 9.1-RELEASE system, by default pkg_add(1) will try to fetch packages from ftp://ftp.freebsd.org/pub/FreeBSD/ports/i386/packages-9.1-release/Latest/. To force pkg_add(1) to download FreeBSD 9-STABLE packages, set PACKAGESITE to ftp://ftp.freebsd.org/pub/FreeBSD/ports/i386/packages-9-stable/Latest/.

Package files are distributed in the .tbz format. Packages are available from ftp://ftp.FreeBSD.org/pub/FreeBSD/ports/packages/ or the /packages directory of the FreeBSD DVD distribution. The layout of the packages directory is similar to that of the /usr/ports tree. Each category has its own directory, and every package can be found within the All directory.

5.4.2. Managing Packages

To list and describe installed packages, use pkg_info(1):

# pkg_info
colordiff-1.0.13    Tool to colorize diff output
docbook-1.4         Meta-port for the different versions of the DocBook DTD

To receive a summary of the versions of all installed packages and a comparison of the installed package versions to the current versions found in the locally installed ports tree, use pkg_version(1):

# pkg_version
colordiff                   =
docbook                     =

The symbols in the second column indicate the relative age of the installed version and the version available in the local ports tree.

=The version of the installed package matches the one in the local ports tree.
<The version of the installed package is older than the one in the local ports tree.
>The version of the installed package is newer than the one in the local ports tree, meaning that the local ports tree is probably out of date.
?The installed package cannot be found in the ports index. This can happen when an installed port is removed from the Ports Collection or is renamed.
*There are multiple versions of the package.
!The installed package exists in the index but for some reason pkg_version was unable to compare the version number of the installed package with the corresponding entry in the index.

5.4.3. Deleting a Package

To remove a previously installed software package, use pkg_delete(1):

# pkg_delete xchat-2.8.8_1

Note that pkg_delete(1) requires the full package name and number and that the above command would not work if xchat was given instead of xchat-2.8.8_1. Use pkg_version(1) to find the version of the installed package, or use a wildcard:

# pkg_delete xchat\*

in this case, all packages whose names start with xchat will be deleted.

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