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

+# DPorts and pkg(8)

-The __pkgng__ 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. In the future, it will be the only binary package manager on FreeBSD just as it is for DPorts.

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

-__pkgng__ 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, __pkgng__ installs only binary packages.

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

-## Getting started with pkgng

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

-DragonFly daily snapshots and Releases (starting with 3.4) come with __pkgng__ already installed. However upgrades from earlier releases won't 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.

+## Getting started with pkg(8)

-To ensure __pkgng__ on a DragonFly BSD 3.4 or higher system is ready for use, run the following BEFORE you try to use `pkg` the first time:

-

- # cd /usr

- # make dports-create

- # rm -rf /usr/pkg

- # pkg upgrade

- # rehash

-

-Since you may need to manually edit the configuration file `/usr/local/etc/pkg.conf` here is the

-usual command to edit it using the vi editor:

-

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

-

-

-

-Before using consult the man page (`man pkg`) and then try things like these examples:

-

-

- # pkg search editors

- # pkg install vim

-

-

-To bootstrap __pkgng__ with a download on a pkgsrc-using system, run:

+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

-Note that this step is unnecessary for any newly installed release from DragonFly 3.4 onwards.

-

-## Configuring the pkgng Environment

+After any installation or reinstallation of the __pkg(8)__ package, you may want to open review the configuration files to customize it, e.g. select a different mirror.

-NOTE: the environment variable is deprecated. This documentation needs updates.

+## Configuring pkg(8)

-The __pkgng__ package management system uses a package repository for most operations. The default package repository location is defined in `/usr/local/etc/pkg.conf` or the `PACKAGESITE` environment variable, which overrides the configuration file. Additional __pkgng__ configuration options are described in pkg.conf(5).

+The __pkg(8)__ program has a configuration file at /usr/local/etc/pkg.conf (the default installation is typically fine and requires no alteration). It uses a a separate location for repository configuration at /usr/local/etc/pkg/repos/ directory.

+For fresh installations, the file /usr/local/etc/pkg/repos/df-latest.conf.sample is copied to /usr/local/etc/pkg/repos/df-latest so that __pkg(8)__ works out of the box. The files ending in the ".sample" extension are ignored; __pkg(8)__ only reads files that end in ".conf" and it will read as many as it finds.

+The default is to use the California-based Avalon, which is also the master. Avalon will have new packages first and they'll be updated as a set. The others are mirrors and may be much, much faster depending on the user's location, but there will be a period between set updates where the mirror is mix of old and new packages.

- PACKAGESITE: http://avalon.dragonflybsd.org/dports/${ABI}/RELEASE

+The simple case is to use a single repository. If you want to switch off the overloaded Avalon, simply change the *enabled* value of Avalon to "no" and enable a new single repository, e.g.:

-The RELEASE repository is static, but the LATEST repository is periodically updated. If bleeding edge is wanted, change pkg.conf to reflect that:

+The provided df-latest.conf may not be up to date. There may be defunct repositories listed and there may be active mirrors that are not listed as options. You may edit or add new repo configuration files as necessary.

-DragonFly users on the development branch can also use pre-built binary packages from the last release, but they will need to override the ABI in pkg.conf, e.g.:

+It is possible to use multiple repositories. The normal use case is that someone builds specific packages (e.g. using poudriere) which should have a higher priority over the official packages. In other words, whenever a package has been built locally, __pkg(8)__ installs the local version and only uses the external repository to install packages not available locally.

- ABI: dragonfly:3.4:x86:32 # for i386 platform

- ABI: dragonfly:3.4:x86:64 # for x86-64 platform

+In the above case, a custom repository configuration file should be created, and it should include the "priority" field, e.g. "priority: 10". The higher the number, the higher the priority. The priority when unspecified is 0.

-There are already a few mirrors available which can be set in pkg.conf

+The last output of "pkg -vv" lists all enable repositories and their priority values.

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

-All the above european mirrors are IPV6-enabled.

+ # pkg search editors

+ # pkg install vim

-## Basic pkgng Operations

+## Basic pkg(8) Operations

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

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

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

+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 pkgng

+## 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 __pkgng__ is installed on the system, run:

+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 pkgng

+## Installing and Removing Packages with pkg(8)

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

@@ -137,11+121,11 @@ Packages that are no longer needed can be removed with `pkg delete`. For example

Proceed with deleting packages [y/N]: y

Deleting curl-7.24.0_1... done

-## Upgrading Installed Packages with pkgng

+## 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 __pkgng__. Suppose a new version of curl has been released. The local package can be upgraded to the new version:

+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

@@ -157,15+141,15 @@ Packages can be upgraded to newer versions with __pkgng__. Suppose a new version

Checking integrity... done

Upgrading curl from 7.24.0 to 7.24.0_1... done

-## Auditing Installed Packages with pkgng

+## Auditing Installed Packages with pkg(8)

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

+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 pkgng Operations

+# Advanced pkg(8) Operations

-## Automatically Removing Leaf Dependencies with pkgng

+## 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:

-__pkgng__ includes its own package database backup mechanism. To manually back up the package database contents, type:

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

- # pkg backup -d <pkgng.db>

+ # pkg backup -d <pkg.db>

-Additionally, __pkgng__ 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).

+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/pkgng.db>

+ # pkg backup -r </path/to/pkg.db>

-## Removing Stale pkgng Packages

+## Removing Stale pkg(8) Packages

-By default, __pkgng__ 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.

+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 pkgng Package Metadata

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

-__pkgng__ has a built-in command to update package origins. 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 __pkgng__, the syntax is:

+_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:

- # pkg set -o <category/oldport>:<category/newport>

+ # 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 -o lang/php5:lang/php53

+ # pkg set -n php5:php53

-As another example, to update lang/ruby18 to lang/ruby19, type:

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

- # pkg set -o lang/ruby18:lang/ruby19

+ # 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 -o graphics/libglut:graphics/freeglut

+ # 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](http://gitweb.dragonflybsd.org/dports.git/blob/HEAD:/UPDATING) 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:

+

+ ALIAS : {

+ 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: