FreeBSD-based distros

By admin, 28 April, 2025

Using pkgng for Binary Package Management

NAME

pkg, pkg-static -- manipulate packages (FreeBSD)

SYNOPSIS

pkg [-v] [-d] [-l] [-N] [-j

pkg [--version] [--debug] [--list] [-N] [--jail

DESCRIPTION

pkg provides an interface for manipulating packages: registering, adding, removing and upgrading packages. pkg-static is a statically linked variant of pkg typically only used for the initial installation of pkg. There are some differences in functionality. See pkg.conf for details.

OPTIONS

The following options are supported by pkg:

-v, --version Display the current version of pkg.

-d, --debug Show debug information.

-l, --list List all the available command names, and exit without performing any other action. The -v option takes precedence over -l but -l will override any other command line arguments.

-o

Set configuration option for pkg from the command line. Options that are set from the environment are redefined. It is permitted to specify this option multiple times.

-N Activation status check mode. Prevent pkg from automatically creating or initializing the SQLite database in /var/db/pkg/local.sqlite if it does not already exist.

Prevent pkg from performing any actions if no packages are currently installed, on the basis that a correctly initialized system using pkg will always have at least the pkg package itself registered.

If used without any other arguments, pkg -N will run the sanity tests and if successful print out a short message showing how many packages are currently installed. The exit status should be a reliable indication of whether a system is configured to use pkg as its package management system or not.

Example usage:

if pkg -N >/dev/null 2>&1; then
# pkgng-specifics
else
# pkg_install-specifics
fi

The -N flag was first released in the /usr/sbin/pkg bootstrapper in FreeBSD 8.4, but was missing from FreeBSD 9.1. It may not be enough to just call pkg -N, as the bootstrapper may be invoked, or an error returned from pkg. The following script is the safest way to detect if pkg is installed and activated:

if TMPDIR=/dev/null ASSUME_ALWAYS_YES=yes
PACKAGESITE=file:///nonexistent
pkg info -x 'pkg(-devel)?$' >/dev/null 2>&1; then
# pkgng-specifics
else
# pkg_install-specifics
fi

-j

pkg will execute in the given

-c

pkg will chroot in the

-r

pkg will install all packages within the specified

-C

pkg will use the specified file as a configuration file.

-R

pkg will search the directory for per-repository configuration files. This overrides any value of REPOS_DIR specified in the main configuration file.

-4 pkg will use IPv4 for fetching repository and packages.

-6 pkg will use IPv6 for fetching repository and packages.

COMMANDS

The following commands are supported by pkg:

help command Display usage information of the specified command.

add Install a package from either a local source or a remote one. When installing from remote source you need to specify the protocol to use when fetching the package. Currently supported protocols are FTP, HTTP and HTTPS.

annotate Add, modify or delete tag-value style annotations on packages.

audit Audit installed packages against known vulnerabilities.

autoremove Delete packages which were automatically installed as dependencies and are not required any more.

backup Dump the local package database to a file specified on the command-line.

bootstrap This is for compatibility with the pkg bootstrapper. If pkg is already installed, nothing is done. If invoked with the -f flag an attempt will be made to reinstall pkg from remote repository.

check Sanity checks installed packages.

clean Clean the local cache of fetched remote packages.

convert Convert to and from the old pkg_add format.

create Create a package.

delete Delete a package from the database and the system.

fetch Fetch packages from a remote repository.

info Display information about installed packages.

install Install a package from a remote package repository. If a package is found in more than one remote repository, then installation happens from the first one. Downloading a package is tried from each package repository in turn, until the package is successfully fetched.

lock Prevent modification or deletion of a package.

plugins List the available plugins.

query Query information about installed packages.

register Register a package in the database.

repo Create a local package repository for remote usage.

rquery Query information for remote repositories.

search Search for the given pattern in the remote package repositories.

set Modify information in the installed database.

shell Open a SQLite shell to the local or remote database. Extreme care should be taken when using this command.

shlib Displays which packages link to a specific shared library.

stats Display package database statistics.

unlock Unlocks packages, allowing them to be modified or deleted.

update Update the available remote repositories as listed in pkg.conf.

updating Display UPDATING entries of installed packages.

upgrade Upgrade a package to a newer version.

version Summarize installed versions of packages.

which Query the database for package(s) that installed a specific file.