PKG(8)

📦 version 2.7.5, in nixos 26.05, nixpkgs unstable

💅 PKG(8) — System Manager's Manual

okay bestie, sit down, hydrate, and let me tell you about pkg(8) and pkg-static — the duo that runs your whole package situation on FreeBSD. we're in section 8 of the manual, system manager territory, so put your big-girl sunglasses on 🕶️


✨ NAME ✨

pkg, pkg-static — manipulate packages 💖


🦋 SYNOPSIS 🦋

pkg [-v] [-d] [-l] [-N] [-o ⟨option=value⟩]
    [-j ⟨jail name or id⟩ | -c ⟨chroot path⟩ | -r ⟨root directory⟩]
    [-C ⟨configuration file⟩] [-R ⟨repository configuration directory⟩]
    [-4 | -6] ⟨command⟩ ⟨flags⟩

and the long-flag glow-up, same energy:

pkg [--version] [--debug] [--list] [-N] [--option ⟨option=value⟩]
    [--jail ⟨jail name or id⟩ | --chroot ⟨chroot path⟩ | --rootdir ⟨root directory⟩]
    [--config ⟨configuration file⟩]
    [--repo-conf-dir ⟨repository configuration directory⟩] [-4 | -6]
    ⟨command⟩ ⟨flags⟩

no cap, those angle brackets are placeholders — swap in your actual values 🌈


🌸 DESCRIPTION 🌸

pkg gives you an interface for manipulating packages — registering, adding, removing and upgrading packages. it's the whole lifecycle, bestie. you want it in, you want it out, you want it updated: pkg handles it.

pkg-static is the statically linked variant of pkg, and it's typically only used for the initial installation of pkg. there are some differences in functionality between the two — check pkg.conf(5) for the details 👀


💅 OPTIONS 💅

here's everything pkg supports, one by one, no skips:

  • -v, --version — display the current version of pkg. specify it twice (-vv) and it also shows you the pkg.conf(5) configuration. double tap for extra tea 🍵
  • -d, --debug — show debug information. when things are weird, this is your flashlight 🔦
  • -l, --list — list all the available command names, then exit without performing any other action. key detail: the -v option takes precedence over -l, but -l will override any other command line arguments.
  • -o ⟨option=value⟩, --option ⟨option=value⟩ — set a configuration option for pkg straight from the command line. options that are set from the environment get redefined by this. and yes, it is permitted to specify this option multiple times — stack 'em 🫶
  • -N — activation status check mode. this one's the main character, so listen up:
    • it prevents pkg from automatically creating or initializing the SQLite database in /var/db/pkg/local.sqlite if it does not already exist.
    • it also prevents pkg from performing any actions if no packages are currently installed — on the basis that a correctly initialised 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
  # pkg(8) specific commands
else
  # other package management system commands
fi
historical lore, because it matters: 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
  # pkg(8) specific commands
else
  # other package management system commands
fi
  • -j ⟨jail name or id⟩, --jail ⟨jail name or id⟩ — pkg will execute in the given ⟨jail name or id⟩, where name matches “jls name” and id matches “jls jid”. see jail(8) and jls(8) 🏝️
  • -c ⟨chroot path⟩, --chroot ⟨chroot path⟩ — pkg will chroot in the ⟨chroot path⟩ environment.
  • -r ⟨root directory⟩, --rootdir ⟨root directory⟩ — pkg will install all packages within the specified ⟨root directory⟩.
  • -C ⟨configuration file⟩, --config ⟨configuration file⟩ — pkg will use the specified file as a configuration file.
  • -R ⟨repo conf dir⟩, --repo-conf-dir ⟨repo conf dir⟩ — 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 — or their unambiguous abbreviations, because we love a shortcut — are supported by pkg:

  • help command — display usage information of the specified command. the "bestie explain" button 🫶
  • add — install a package from either a local source or a remote one. when installing from a 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 🏷️
  • alias — list the command line aliases.
  • audit — audit installed packages against known vulnerabilities. stay safe out there 💀
  • autoremove — delete packages which were automatically installed as dependencies and are not required any more.
  • bootstrap — this is for compatibility with the pkg(7) bootstrapper. if pkg is already installed, nothing is done. if invoked with the -f flag, an attempt will be made to reinstall pkg from a remote repository.
  • check — sanity checks installed packages.
  • clean — clean the local cache of fetched remote packages. self-care 🧹
  • 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 and package files.
  • install — install a package from a package repository or a local archive. if a package is found in more than one repository, then the first one is used. if not local, then a download is attempted from each repository, until the package is successfully fetched.
  • lock — prevent modification or deletion of a package. nobody touch, it's protected 🔒
  • plugins — list the available plugins.
  • query — query information about installed packages and package files.
  • 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. fr fr, this is the sharpest tool in the drawer, do not go poking around in there for fun 🙈
  • 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(5).
  • 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.

🌈 ENVIRONMENT 🌈

all configuration options from pkg.conf(5) can be passed as environment variables 🫶

extra environment variables are:

  • INSTALL_AS_USER — allow all manipulation to be done as a regular user instead of checking for root credentials when appropriate. it is expected that the user will ensure that every file and directory manipulated by pkg are readable (or writable where appropriate) by the user.

🎀 FILES 🎀

see pkg.conf(5).


⭐ EXAMPLES ⭐

search for a package:

% pkg search perl

install a package:

% pkg install perl-5.14
installing must specify a unique origin or version — otherwise it will try installing all matches. don't do that to yourself 😭

list installed packages:

% pkg info

upgrade from remote repository:

% pkg upgrade

change the origin for an installed package:

% pkg set -o lang/perl5.12:lang/perl5.14
% pkg install -Rf lang/perl5.14

list non-automatic packages:

% pkg query -e '%a = 0' %o

list automatic packages:

% pkg query -e '%a = 1' %o

delete an installed package:

% pkg delete perl-5.14

remove unneeded dependencies:

% pkg autoremove

change a package from automatic to non-automatic, which will prevent autoremove from removing it:

% pkg set -A 0 perl-5.14

change a package from non-automatic to automatic, which will make autoremove allow it be removed once nothing depends on it:

% pkg set -A 1 perl-5.14

create package file from an installed package:

% pkg create -o /usr/ports/packages/All perl-5.14

determine which package installed a file:

% pkg which /usr/local/bin/perl

audit installed packages for security advisories:

% pkg audit

check installed packages for checksum mismatches:

# pkg check -s -a

check for missing dependencies:

# pkg check -d -a

show the pkg-message of a package:

# pkg info -D perl-5.14

restore a backup database:

% rm /var/db/pkg/local.sqlite
% xzcat /var/backups/pkg.sql.xz | pkg shell

🦋 SEE ALSO 🦋

pkg_create(3), pkg_printf(3), pkg_repo_create(3), pkg_repos(3), pkg-keywords(5), pkg-lua-script(5), pkg-repository(5), pkg-script(5), pkg-triggers(5), pkg.conf(5), pkg-add(8), pkg-alias(8), pkg-annotate(8), pkg-audit(8), pkg-autoremove(8), pkg-check(8), pkg-clean(8), pkg-config(8), pkg-create(8), pkg-delete(8), pkg-fetch(8), pkg-help(8), pkg-info(8), pkg-install(8), pkg-key(8), pkg-lock(8), pkg-plugins(8), pkg-query(8), pkg-register(8), pkg-repo(8), pkg-repositories(8), pkg-rquery(8), pkg-search(8), pkg-set(8), pkg-shell(8), pkg-shlib(8), pkg-ssh(8), pkg-stats(8), pkg-triggers(8), pkg-unregister(8), pkg-update(8), pkg-updating(8), pkg-upgrade(8), pkg-version(8), pkg-which(8)

to build your own package set for one or multiple servers see

FreeBSD pkg mirror: https://pkg.freebsd.org your closest pkg mirror based on MaxMind GeoLite geo-DNS 🌍


🔥 HISTORY 🔥

the pkg command first appeared in FreeBSD 9.1.


💜 AUTHORS AND CONTRIBUTORS 💜

iconic lineup, every single one of them:

Baptiste Daroussin <bapt@FreeBSD.org>, Julien Laffaye <jlaffaye@FreeBSD.org>, Philippe Pepiot <phil@philpep.org>, Will Andrews <will@FreeBSD.org>, Marin Atanasov Nikolov <dnaeon@gmail.com>, Yuri Pankov <yuri.pankov@gmail.com>, Alberto Villa <avilla@FreeBSD.org>, Brad Davis <brd@FreeBSD.org>, Matthew Seaman <matthew@FreeBSD.org>, Bryan Drewery <bryan@shatow.net>, Eitan Adler <eadler@FreeBSD.org>, Romain Tartière <romain@FreeBSD.org>, Vsevolod Stakhov <vsevolod@FreeBSD.org>, Alexandre Perrin <alex@kaworu.ch>


okay we are not done yet bestie, there's more of this page coming — stay tuned 💅✨

🐛 BUGS 🐛

okay so bestie, sometimes things are just... not it 😭 and that's literally why this section exists.

  • found a bug? the place to go is the issue tracker at https://github.com/freebsd/pkg/issues — drop it in there so everyone can see it and someone can slay it 🔥
  • got a question, or just wanna talk it out with actual humans instead of a bug form? send it over to the pkg@FreeBSD.org mailing list 💌 they're the ones who know, iykyk
no cap, the tracker is for bugs, the mailing list is for questions and issues — matching the right channel is main character energy and makes everyone's life easier 🫶

and that's a wrap, babe 💅✨ this lil page comes to you from Debian, dated December 13, 2025, and it's filed under PKG(8) — go forth and pkg responsibly, mwah 🎀🦋💖

📦 where this page comes from