DragonFly BSD


DPorts and pkg(8)

DPorts is DragonFly's own third-party software build system. It is based on FreeBSD's Ports Collection. Differences between ports and DPorts are intentionally kept to a minimum, both to maintain familiarity for mutual users of both operating systems and also to leverage the tremendous amount of work the FreeBSD contributors put into ports. DPorts can and does feature ports unique to DragonFly, so it's truly a native system.

The pkg(8) tool called "pkg" is a modern and fast binary package manager. It was developed for FreeBSD, but PC-BSD used it in production first, followed soon after by DragonFly. FreeBSD has since removed their legacy tools so pkg(8) is exclusively used by FreeBSD as well.

pkg(8) is not a replacement for port management tools like ports-mgmt/portmaster or ports-mgmt/portupgrade. While ports-mgmt/portmaster and ports-mgmt/portupgrade can install third-party software from both binary packages and DPorts, pkg(8) installs only binary packages. On the other hand, many people use pkg(8) by itself and never install the optional portupgrade or portmaster tools.

Getting started with pkg(8)

DragonFly daily snapshots and Releases (starting with 3.4) come with pkg(8) already installed. Upgrades from earlier releases, however, will not have it. If the "pkg" program is missing on the system for any reason, it can be quickly bootstrapped without having to build it from source or even having dports installed:

# make pkg-bootstrap
# rehash
# pkg-static install -y pkg
# rehash

If pkgsrc has ever been installed on the system, make sure all binaries produced by it have been removed:

# rm -rf /usr/pkg

Currently it's necessary to manually install the configuration file, but this requirement should disappear in the future. After installing the configuration file, you may want to open it up and edit it to select a different mirror.

Configuring pkg(8)

Older versions of pkg(8) saved their configuration at /usr/local/etc/pkg.conf; this file made reference to a PACKAGESITE. pkg(8) will still work based on this file, but will output errors:

# pkg update
pkg: PACKAGESITE in pkg.conf is deprecated. Please create a repository configuration file
Updating repository catalogue
pkg: Warning: use of http:// URL scheme with SRV records is deprecated: switch to pkg+http://

If you do not see these errors, then skip to "Now, navigate to /usr/local/etc/pkg/repos/", otherwise:

Listen to the errors: hash out the packagesite line, save the file, and move on. This can be done with vi:

# vi /usr/local/etc/pkg.conf

There will be two lines in the file like this:

# Default DPorts package server (California)
PACKAGESITE: http://mirror-master.dragonflybsd.org/dports/${ABI}/LATEST

Hash out the offending line:

# Default DPorts package server (California)
# PACKAGESITE: http://mirror-master.dragonflybsd.org/dports/${ABI}/LATEST

Note that, as of time of writing, there are two working package repositories:

# Default DPorts package server (California)
# PACKAGESITE: http://mirror-master.dragonflybsd.org/dports/${ABI}/LATEST

# European mirrors
#PACKAGESITE: http://dfly.schlundtech.de/dports/${ABI}/LATEST

Test their performance---we will be using the fastest one. This may, or may not, be the one closest to you (the California site for the New World, the German site for the Old World).

# ping schlundtech.de
PING schlundtech.de ( 56 data bytes
64 bytes from icmp_seq=0 ttl=49 time=101.433 ms
64 bytes from icmp_seq=1 ttl=49 time=59.177 ms
64 bytes from icmp_seq=2 ttl=49 time=79.550 ms
64 bytes from icmp_seq=3 ttl=49 time=88.268 ms
64 bytes from icmp_seq=4 ttl=49 time=120.060 ms
--- schlundtech.de ping statistics ---
20 packets transmitted, 19 packets received, 5.0% packet loss
round-trip min/avg/max/stddev = 49.555/96.064/186.662/33.559 ms
# ping mirror-master.dragonflybsd.org
PING avalon.dragonflybsd.org ( 56 data bytes
64 bytes from icmp_seq=0 ttl=47 time=208.013 ms
64 bytes from icmp_seq=1 ttl=47 time=256.441 ms
64 bytes from icmp_seq=2 ttl=47 time=281.436 ms
64 bytes from icmp_seq=3 ttl=47 time=281.103 ms
64 bytes from icmp_seq=4 ttl=47 time=285.440 ms
--- avalon.dragonflybsd.org ping statistics ---
19 packets transmitted, 19 packets received, 0.0% packet loss
round-trip min/avg/max/stddev = 208.013/264.017/334.180/31.549 ms

Now, navigate to /usr/local/etc/pkg/repos/ and rename one of the configuration file samples you find there. df-latest.conf will make pkg use the newest available binaries while df-release.conf points to binaries built at the time of the release. The latter is frozen so you will not get any updates. Edit the one you renamed:

# cd /usr/local/etc/pkg/repos/
# ls
df-latest.conf.sample   df-releases.conf.sample
# cp -v df-latest.conf.sample df-latest.conf
df-latest.conf.sample -> df-latest.conf
# chmod -v 644 df-latest.conf
# vi df-latest.conf

Enable whichever server was faster (Avalon is American, SchlundTech is German), and pkg+ to the url and SRV to mirror_type:

Avalon: {
    url             : pkg+http://mirror-master.dragonflybsd.org/dports/${ABI}/LATEST,
    mirror_type     : SRV
    enabled         : no
SchlundTech: {
    url             : pkg+http://dfly.schlundtech.de/dports/${ABI}/LATEST,
    mirror_type     : SRV
    enabled         : yes

Before using, consult the man page (man pkg) and then try these examples:

# pkg search editors
# pkg install vim

Basic pkg(8) Operations

Usage information for pkg(8) is available in the pkg(8) manual page, or by running pkg without additional arguments.

Each pkg(8) command argument is documented in a command-specific manual page. To read the manual page for pkg install, for example, run either:

# pkg help install
# man pkg-install

Obtaining Information About Installed Packages with pkg(8)

Information about the packages installed on a system can be viewed by running pkg info. Similar to pkg_info(1), the package version and description for all packages will be listed. Information about a specific package is available by running:

# pkg info packagename

For example, to see which version of pkg(8) is installed on the system, run:

# pkg info pkg
pkg-1.0.12                   New generation package manager

Installing and Removing Packages with pkg(8)

In general, most DragonFly users will install binary packages by typing:

# pkg install <packagename>

For example, to install curl:

# pkg install curl

Updating repository catalogue
Repository catalogue is up-to-date, no need to fetch fresh copy
The following packages will be installed:

    Installing ca_root_nss: 3.13.5
    Installing curl: 7.24.0

The installation will require 4 MB more space

1 MB to be downloaded

Proceed with installing packages [y/N]: y
ca_root_nss-3.13.5.txz           100%    255KB   255.1KB/s  255.1KB/s   00:00
curl-7.24.0.txz                  100%   1108KB     1.1MB/s    1.1MB/s   00:00
Checking integrity... done
Installing ca_root_nss-3.13.5... done
Installing curl-7.24.0... 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.13.5    The root certificate bundle from the Mozilla Project
curl-7.24.0           Non-interactive tool to get files from FTP, GOPHER, HTTP(S) servers
pkg-1.0.12            New generation package manager

Packages that are no longer needed can be removed with pkg delete. For example, if it turns out that curl is not needed after all:

# pkg delete curl
The following packages will be deleted:


The deletion will free 3 MB

Proceed with deleting packages [y/N]: y
Deleting curl-7.24.0_1... done

Upgrading Installed Packages with pkg(8)

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.

Packages can be upgraded to newer versions with pkg(8). Suppose a new version of curl has been released. The local package can be upgraded to the new version:

# pkg upgrade
Updating repository catalogue
repo.txz            100%    297KB   296.5KB/s   296.5KB/s   00:00
The following packages will be upgraded:

Upgrading curl: 7.24.0 -> 7.24.0_1

1 MB to be downloaded

Proceed with upgrading packages [y/N]: y
curl-7.24.0_1.txz   100%    1108KB  1.1MB/s       1.1MB/s   00:00
Checking integrity... done
Upgrading curl from 7.24.0 to 7.24.0_1... done

Auditing Installed Packages with pkg(8)

Occasionally, software vulnerabilities may be discovered in software within DPorts. pkg(8) includes built-in auditing. To audit the software installed on the system, type:

# pkg audit -F

Advanced pkg(8) Operations

Automatically Removing Leaf Dependencies with pkg(8)

Removing a package may leave behind unnecessary dependencies, like security/ca_root_nss in the example above. Such packages are still installed, but nothing depends on them any more. Unneeded packages that were installed as dependencies can be automatically detected and removed:

# pkg autoremove
Packages to be autoremoved:

The autoremoval will free 723 kB

Proceed with autoremoval of packages [y/N]: y
Deinstalling ca_root_nss-3.13.5... done

Backing Up the pkg(8) Package Database

pkg(8) includes its own package database backup mechanism. To manually back up the package database contents, type:

# pkg backup -d <pkg.db>

Additionally, pkg(8) includes a periodic(8) script to automatically back up the package database daily if daily_backup_pkgng_enable is set to YES in periodic.conf(5). To prevent the pkg_install periodic script from also 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/pkg.db>

Removing Stale pkg(8) Packages

By default, pkg(8) stores binary packages in a cache directory as 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 the outdated binary packages, type:

# pkg clean

Modifying pkg(8) Package Metadata

pkg(8) has a couple of built-in commands to update package origins.

Note: Previously it was recommended to use the -o option, e.g. "-o < category / oldport >:< category / newport >" but this option is deprecated and will be removed in the future.

Note: The --change-name (-n) option requires the package name. Normally it's intuitive based on the name of the port, but not always. To get the definitive name, the following command can be used:

# make -V PKGBASE -C /usr/dports/<category>/<portname>

For example, if lang/php5 was originally at version 5.3, but has been renamed to lang/php53 for the inclusion of version 5.4, the package database can be updated to deal with this. For pkg(8), the syntax is:

# pkg set -n <oldname>:<newname>

For example, to change the package origin for the above example, type:

# pkg set -n php5:php53

As another example, to update lang/ruby20 to lang/ruby21 (the current default), type:

# pkg set -n ruby20:ruby

As a final example, to change the origin of the libglut shared libraries from graphics/libglut to graphics/freeglut, type:

# pkg set -n libglut:freeglut

Note: When changing package origins, in most cases it is important to reinstall packages that are dependent on the package that has had the origin changed. To force a reinstallation of dependent packages, type:

# pkg install -Rf graphics/freeglut

Bullet-proof (conflict-proof) upgrade technique

Several people have run into problem upgrading binary packages when default versions change (e.g. PHP default changes from version 5.4 to 5.6, or PostgreSQL default changes from 9.0 to 9.2). Usually there are upgrading hints at /usr/dports/UPDATING, but there are issues with this method of communication

  1. You must have /usr/dports installed and current, which kind of defeats the purpose of using binary packages
  2. You usually don't go looking there until after you hit a failure
  3. Proactively reading /usr/dports/UPDATING perhaps from DragonFly's Gitweb would be the best approach, but honestly nobody is going to do that.

Additionally, over time Administrators install packages to evaluate them or otherwise don't need them any longer, but often the Administrators forget to remove the package and its dependencies later. These extra packages still get upgraded unnecessarily.

Technique Instructions

The following technique will guarantee conflict-proof, integral updates and at the same time allow manually pruning of unwanted packages.

Step 1: Get list of primary packages

For pkg(8) version 1.5.1 or later, the "prime-list" alias is predefined in the pre-installed pkg.conf, so you can run the following command:

> pkg prime-list > ~/prime.list

If you are using an older version of package, or already had pkg.conf which was not overwritten, you can use the equivalent of the alias like so:

> pkg query -e "%a = 0" "%n" > ~/prime.list

The file ~/prime.list contains the list of packages that were manually installed. For example, if an Administrator only requested on package to be installed, Libreoffice, pkg(8) might pull in 200 dependencies, but ~/prime.list would only contain the name of a single package.

Step 2: Review and edit primary package list

Using your favorite editor, load ~/prime.list, which indicates which packages were manually installed. If there are any packages that are no longer desired, simple delete the line that contains it.

Step 3: Wipe everything out

Now everything except package needs to be removed off the system.

> pkg delete -ay

Step 4: Upgrade the repository category

What we really want to do here is update the repository catalog, but if there's a newer version of pkg(8), we can upgrade it at the same time.

> pkg upgrade

Say yes if pkg(8) wants permission to update itself on the system.

Step 5: Cleanse the package cache

To avoid any possible reinstallation of a stale package, we want to remove obsolete packages from the cache.

> pkg clean -y

Step 6: Reinstall the primary packages

Now we reinstall the packages that we really want on the system and let pkg(8) pull in the dependencies that are needed without fear of conflict.

> pkg install `cat ~/prime.list`

Provide affirmative answers to any confirmations pkg(8) asks.

How to create the prime-list alias for future use

Rather than try to remember that hard-to-type query, it's more convenient to define this command as an alias. Note this is not necessary for new installations since around 22 April 2015 (The alias is predefined for pkg(8) version 1.5.1 and later). To defined the alias, create or append the /usr/local/etc/pkg.conf file with the following:

  prime-list: query -e "%a = 0" "%n",

If ALIAS is already defined, just add the prime-list line to the list. You may review /usr/local/etc/pkg.conf.sample for other ALIAS suggestions. There are several useful ones offered there.

Building DPorts from source

The average user will probably not build packages from source. However, it's easy to do and it can be done even when packages have already been pre-installed on the system. Common reasons to build from source are:

Installing DPorts tree

DragonFly 3.4 or later is the minimum version that can build DPorts from source.

It's probably that pkgsrc binaries are already installed because it comes bootstrapped with new systems. It is necessary to rename /usr/pkg directory so that the existing pkgsrc binary tools and libraries don’t get accidentally used while building DPorts, causing breakage. For the installation of the DPorts tree, type:

# cd /usr
# make dports-create-shallow

If the /usr/pkg directory has already been renamed, git won’t be in the search path any more. One option is to download a tarball of DPorts and unpack it. To do this, type:

# cd /usr
# make dports-download

For future updates, pull delta changes via git is fastest, so it is suggested to convert the static tree to a git repository by typing:

# cd /usr/dports/devel/git
# make install
# cd /usr
# rm -rf /usr/dports
# make dports-create-shallow

The git repository is hosted on the github account of John Marino.

Final thoughts

Building from source works similar to ports and pkgsrc: cd into the appropriate program's directory, and type 'make'. 'make install' to install the software, 'make clean' to clean up work files, and so on. Use 'make config-recursive' if you want to set all the port's options, and the options of its dependencies, immediately instead of during the build.

To take all the default build options and avoid getting the pop-up dialog box, set NO_DIALOG=yes on either the command line or the make.conf file.

If you just want to set the options for one package, and accept the default for all of its dependencies, do 'make config' in the package in you want non-default options, and then 'make NO_DIALOG=yes'. Note that this is only necessary if you want to build from source with a non-default set of options, or if no pre-built binary package is available yet.

More reading