DragonFly On-Line Manual Pages
PKG(8) DragonFly System Manager's Manual PKG(8)
pkg, pkg-static - manipulate packages
pkg [-v] [-d] [-l] [-N] [-j <chroot path> | -r <root directory>]
[-C <configuration file>] [-R <repository configuration directory>]
[-4 | -6] <command> <flags>
pkg [--version] [--debug] [--list] [-N]
[--jail <jail name or id> |
--chroot <chroot path> | --rootdir <root directory>]
[--config <configuration file>]
[--repo-conf-dir <repository configuration directory>] [-4 | -6]
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(5) for
The following options are supported by pkg:
Display the current version of pkg.
Show debug information.
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 <option=value>, --option <option=value>
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 initialised
system using pkg will always have at least the pkg package itself
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.
if pkg -N >/dev/null 2>&1; then
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 \
pkg info -x 'pkg(-devel)?$' >/dev/null 2>&1; then
-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
-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.
The following commands (or their unambiguous abbreviations) are supported
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.
Add, modify or delete tag-value style annotations on packages.
alias List the command line aliases.
audit Audit installed packages against known vulnerabilities.
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
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 remote repository.
check Sanity checks installed packages.
clean Clean the local cache of fetched remote packages.
Convert to and from the old pkg_add(1) 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 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
lock Prevent modification or deletion of a package.
List the available plugins.
query Query information about installed packages.
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
Display UPDATING entries of installed packages.
Upgrade a package to a newer version.
Summarize installed versions of packages.
which Query the database for package(s) that installed a specific file.
All configuration options from pkg.conf(5) can be passed as environment
Extra environment variables are:
INSTALL_AS_USER Allow all manipulation to be done as a regular user
instead of checking for root credentials when
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.
Search for a package:
$ pkg search perl
Install a package:
Installing must specify a unique origin or version otherwise it
will try installing all matches.
% pkg install perl-5.14
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/dports/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
pkg_printf(3), pkg_repos(3), pkg-lua-script(5), pkg-repository(5),
pkg-script(5), pkg.conf(5), pkg-add(8), pkg-alias(8), pkg-annotate(8),
pkg-audit(8), pkg-autoremove(8), pkg-backup(8), pkg-check(8),
pkg-clean(8), pkg-config(8), pkg-create(8), pkg-delete(8), pkg-fetch(8),
pkg-info(8), pkg-install(8), pkg-lock(8), pkg-query(8), pkg-register(8),
pkg-repo(8), pkg-rquery(8), pkg-search(8), pkg-set(8), pkg-shell(8),
pkg-shlib(8), pkg-ssh(8), pkg-stats(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.
The pkg command first appeared in FreeBSD 9.1.
AUTHORS AND CONTRIBUTORS
Baptiste Daroussin <bapt@FreeBSD.org>, Julien Laffaye
<jlaffaye@FreeBSD.org>, Philippe Pepiot <firstname.lastname@example.org>, Will Andrews
<will@FreeBSD.org>, Marin Atanasov Nikolov <email@example.com>, Yuri
Pankov <firstname.lastname@example.org>, Alberto Villa <avilla@FreeBSD.org>, Brad
Davis <brd@FreeBSD.org>, Matthew Seaman <matthew@FreeBSD.org>, Bryan
Drewery <email@example.com>, Eitan Adler <eadler@FreeBSD.org>, Romain
Tarti`ere <romain@FreeBSD.org>, Vsevolod Stakhov <vsevolod@FreeBSD.org>,
Alexandre Perrin <firstname.lastname@example.org>
See the issue tracker at https://github.com/freebsd/pkg/issues
Please direct questions and issues to the pkg@FreeBSD.org mailing list.
DragonFly 5.9-DEVELOPMENT March 18, 2020 DragonFly 5.9-DEVELOPMENT
pkg_mkIndex(n) Tcl Built-In Commands pkg_mkIndex(n)
pkg_mkIndex - Build an index for automatic loading of packages
pkg_mkIndex ?options...? dir ?pattern pattern ...?
Pkg_mkIndex is a utility procedure that is part of the standard Tcl
library. It is used to create index files that allow packages to be
loaded automatically when package require commands are executed. To
use pkg_mkIndex, follow these steps:
 Create the package(s). Each package may consist of one or more
Tcl script files or binary files. Binary files must be suitable
for loading with the load command with a single argument; for
example, if the file is test.so it must be possible to load this
file with the command load test.so. Each script file must
contain a package provide command to declare the package and
version number, and each binary file must contain a call to
 Create the index by invoking pkg_mkIndex. The dir argument
gives the name of a directory and each pattern argument is a
glob-style pattern that selects script or binary files in dir.
The default pattern is *.tcl and *.[info sharedlibextension].
Pkg_mkIndex will create a file pkgIndex.tcl in dir with package
information about all the files given by the pattern arguments.
It does this by loading each file into a slave interpreter and
seeing what packages and new commands appear (this is why it is
essential to have package provide commands or Tcl_PkgProvide
calls in the files, as described above). If you have a package
split among scripts and binary files, or if you have
dependencies among files, you may have to use the -load option
or adjust the order in which pkg_mkIndex processes the files.
See COMPLEX CASES below.
 Install the package as a subdirectory of one of the directories
given by the tcl_pkgPath variable. If $tcl_pkgPath contains
more than one directory, machine-dependent packages (e.g., those
that contain binary shared libraries) should normally be
installed under the first directory and machine-independent
packages (e.g., those that contain only Tcl scripts) should be
installed under the second directory. The subdirectory should
include the package's script and/or binary files as well as the
pkgIndex.tcl file. As long as the package is installed as a
subdirectory of a directory in $tcl_pkgPath it will
automatically be found during package require commands.
If you install the package anywhere else, then you must ensure
that the directory containing the package is in the auto_path
global variable or an immediate subdirectory of one of the
directories in auto_path. Auto_path contains a list of
directories that are searched by both the auto-loader and the
package loader; by default it includes $tcl_pkgPath. The
package loader also checks all of the subdirectories of the
directories in auto_path. You can add a directory to auto_path
explicitly in your application, or you can add the directory to
your TCLLIBPATH environment variable: if this environment
variable is present, Tcl initializes auto_path from it during
 Once the above steps have been taken, all you need to do to use
a package is to invoke package require. For example, if
versions 2.1, 2.3, and 3.1 of package Test have been indexed by
pkg_mkIndex, the command package require Test will make version
3.1 available and the command package require -exact Test 2.1
will make version 2.1 available. There may be many versions of
a package in the various index files in auto_path, but only one
will actually be loaded in a given interpreter, based on the
first call to package require. Different versions of a package
may be loaded in different interpreters.
The optional switches are:
-direct The generated index will implement direct loading of the
package upon package require. This is the default.
-lazy The generated index will manage to delay loading the
package until the use of one of the commands provided by
the package, instead of loading it immediately upon
package require. This is not compatible with the use of
auto_reset, and therefore its use is discouraged.
-load pkgPat The index process will pre-load any packages that exist
in the current interpreter and match pkgPat into the
slave interpreter used to generate the index. The
pattern match uses string match rules, but without
making case distinctions. See COMPLEX CASES below.
-verbose Generate output during the indexing process. Output is
via the tclLog procedure, which by default prints to
-- End of the flags, in case dir begins with a dash.
PACKAGES AND THE AUTO-LOADER
The package management facilities overlap somewhat with the auto-
loader, in that both arrange for files to be loaded on-demand.
However, package management is a higher-level mechanism that uses the
auto-loader for the last step in the loading process. It is generally
better to index a package with pkg_mkIndex rather than auto_mkindex
because the package mechanism provides version control: several
versions of a package can be made available in the index files, with
different applications using different versions based on package
require commands. In contrast, auto_mkindex does not understand
versions so it can only handle a single version of each package. It is
probably not a good idea to index a given package with both pkg_mkIndex
and auto_mkindex. If you use pkg_mkIndex to index a package, its
commands cannot be invoked until package require has been used to
select a version; in contrast, packages indexed with auto_mkindex can
be used immediately since there is no version control.
HOW IT WORKS
Pkg_mkIndex depends on the package unknown command, the package
ifneeded command, and the auto-loader. The first time a package
require command is invoked, the package unknown script is invoked.
This is set by Tcl initialization to a script that evaluates all of the
pkgIndex.tcl files in the auto_path. The pkgIndex.tcl files contain
package ifneeded commands for each version of each available package;
these commands invoke package provide commands to announce the
availability of the package, and they setup auto-loader information to
load the files of the package. If the -lazy flag was provided when the
pkgIndex.tcl was generated, a given file of a given version of a given
package is not actually loaded until the first time one of its commands
is invoked. Thus, after invoking package require you may not see the
package's commands in the interpreter, but you will be able to invoke
the commands and they will be auto-loaded.
Some packages, for instance packages which use namespaces and export
commands or those which require special initialization, might select
that their package files be loaded immediately upon package require
instead of delaying the actual loading to the first use of one of the
package's command. This is the default mode when generating the package
index. It can be overridden by specifying the -lazy argument.
Most complex cases of dependencies among scripts and binary files, and
packages being split among scripts and binary files are handled OK.
However, you may have to adjust the order in which files are processed
by pkg_mkIndex. These issues are described in detail below.
If each script or file contains one package, and packages are only
contained in one file, then things are easy. You simply specify all
files to be indexed in any order with some glob patterns.
In general, it is OK for scripts to have dependencies on other
packages. If scripts contain package require commands, these are
stubbed out in the interpreter used to process the scripts, so these do
not cause problems. If scripts call into other packages in global
code, these calls are handled by a stub unknown command. However, if
scripts make variable references to other package's variables in global
code, these will cause errors. That is also bad coding style.
If binary files have dependencies on other packages, things can become
tricky because it is not possible to stub out C-level APIs such as
Tcl_PkgRequire API when loading a binary file. For example, suppose
the BLT package requires Tk, and expresses this with a call to
Tcl_PkgRequire in its Blt_Init routine. To support this, you must run
pkg_mkIndex in an interpreter that has Tk loaded. You can achieve this
with the -load pkgPat option. If you specify this option, pkg_mkIndex
will load any packages listed by info loaded and that match pkgPat into
the interpreter used to process files. In most cases this will satisfy
the Tcl_PkgRequire calls made by binary files.
If you are indexing two binary files and one depends on the other, you
should specify the one that has dependencies last. This way the one
without dependencies will get loaded and indexed, and then the package
it provides will be available when the second file is processed. You
may also need to load the first package into the temporary interpreter
used to create the index by using the -load flag; it will not hurt to
specify package patterns that are not yet loaded.
If you have a package that is split across scripts and a binary file,
then you should avoid the -load flag. The problem is that if you load a
package before computing the index it masks any other files that
provide part of the same package. If you must use -load, then you must
specify the scripts first; otherwise the package loaded from the binary
file may mask the package defined by the scripts.
auto-load, index, package, version
Tcl 8.3 pkg_mkIndex(n)