NextGeneration package management tools for FreeBSD
Switch branches/tags
Nothing to show
Pull request Compare This branch is 377 commits ahead, 6855 commits behind freebsd:master.
Latest commit a7fe3d0 Oct 14, 2011 @bapt bapt Fix upgrade

pkgng - a binary package manager for FreeBSD

Table of Contents:


pkgng is built on top of libpkg, a new library to interface with package registration backends. It abstracts package management details such as registration, remote repositories, package creation, updating, etc.

pkgng package format

pkgng package format is a tar archive which can be raw, or use the following compression: gz, bzip2 and xz, defaulting in xz format.

The tar it self is composed in two types of elements:

  • the special files at the begining of the archive, starting with a "+"
  • the datas.

The metadata

pkgng supports two files for metadata:

  • +MTREE_DIRS (optional)

The manifest is in YAML format, it contains all the information about the package:

name: foo
version: 1.0
origin: category/foo
comment: this is foo package
arch: i386
osversion: 8.2-STABLE-802507
prefix: /usr/local
licenselogic: or
licenses: [MIT, MPL]
flatsize: 482120
users: [USER1, USER2]
groups: [GROUP1, GROUP2]
options: { OPT1: off, OPT2: on }
desc: |-
  This is the descrpition
  Of foo
  A component of bar
categories: [bar, plop]
  libiconv: {origin: converters/libiconv, version: 1.13.1_2}
  perl: {origin: lang/perl5.12, version: 5.12.4 }
  /usr/local/bin/foo: 'sha256sum'
  /usr/local/bin/i_am_a_link: '-'
  /usr/local/share/foo-1.0/foo.txt: 'sha256sum'
- /usr/local/share/foo-1.0
  post-install: |-
    echo post-install
  pre-install: |-
    echo pre-install

Valid scripts are:

  • pre-install
  • post-install
  • install
  • pre-deinstall
  • post-deinstall
  • deinstall
  • pre-upgrade
  • post-upgrade
  • upgrade

Script MUST be in sh format nothing else would work. shebang is not necessary.

When the manifest is read by pkg_create files and dirs accept another format:

  /usr/local/bin/foo, 'sha256sum'
  /usr/local/bin/bar: {sum: 'sha256sum', uname: baruser, gname: foogroup, perm: 0644 }
- /usr/local/share/foo-1.0
- /path/to/directory: {uname: foouser, gname: foogroup, perm: 0755}

This allows to override the users, groups and mode that pkgng file find when This allows to override the users, groups and mode of files and directories during package creation, like for example this allows to create a package containing root files without being packaged by the root user.


This is optional, this is used by the package the same way it is done by the legacy tools which means the MTREE is extracted in prefix before each installation.

In the future we hope that mtree will be deprecated in favour of a hier package or in single MTREE that won't be customisable in per package basis and because pkgng supports packing of empty directories, per package MTREE makes no sense anymore.

Local database

Once a package is installed, it is registered to a SQLite database.

The SQLite database allow fast queries and ACID transactions. It also allow to query the reverse dependencies without a +REQUIRED_BY hack.

In order to save space the MTREE is only stored once, which save 18K per installed package.

pkgng supports a `register' command to register packages into the SQLite database from the ports. The register command can execute the install script, show pkg-message, ...

Installation of packages

`pkg add' can install a package archive from the local disk, or from a remote FTP/HTTP server.

If only a package name is given, it will search the remote repository and download and install the package if it exists. The dependencies will be downloaded and installed first.

This is possible because we have the dependencies informations in the remote repository database.

`pkg add' will check if the user attempts to install a package built for another arch or release.

Upgrades of packages

pkgng will also support upgrades of binary packages.

pkgng will compare the versions of installed packages and those available on the repository. It will compute the proper update order and apply them.

Deletion packages

Directory leftovers are automatically removed if they are not in the MTREE.

pkgng in Ports

To use pkgng from ports currently we need to include in, the line before .if defined(USE_LOCAL_MK)

You can also simply run this command after having install to your /usr/ports/Mk diretory or the suitable PORTSDIR:

$> sed -i'' -e '/.if.*USE_LOCAL_MK.*$/{G;s/\(.if.*USE_LOCAL_MK)\)\(\n\)/.include "${PORTSDIR}\/Mk\/"\2\1/;}' /usr/ports/Mk/

A quick usage introduction to pkgng

In this section of the document we will try to give a quick and dirty introduction on the practical usage of pkgng - installing packages, searching in remote package repositories, updating remote package repositories and installing from them, etc.

Installing pkgng

The first thing to start with is to get pkgng installed on your machine.

You can grap a development snapshot of pkgng from the pkgng Github repository

To get the latest version of pkgng from the Git repo, just clone it:

# git clone

Or you can take an already tagged release of pkgng from the above web page as well.

Just open your browser and download the release you want.

Once you have the pkgng sources, installing it is fairly easy:

# cd pkgng
# make && make install && make clean

Now you should have pkgng installed on your system.

Transferring your packages to pkgng is done by the ports/pkg2ng script.

In order to register your installed packages to pkgng, execute the commands below:

# cd pkgng/ports
# sh pkg2ng

Getting help on the commands usage

In order to get help on any of the pkgng commands you should use the 'pkg help ' command, which will take the man page of the specified command.

In order to get the available commands in pkgng, just execute 'pkg help'

# pkg help 
# pkg help <command>

Installing packages

Packages can be installed from either a local directory on the file system or from a remote location using the FTP/HTTP protocol in order to fetch the packages.

In order to install the package foo-1.2.3 from a local directory, you will use a command similar to the following below:

# pkg add /path/to/packages/foo-1.2.3.txz

You need to make sure that all dependencies of foo-1.2.3 are also in the directory, which you use in order to install the package.

You can also install the package foo-1.2.3 from a remote location using the FTP/HTTP protocol. In order to do that you could use a command similar to the following:

# pkg add

This will also install the package foo-1.2.3 and it's dependencies from the remote server using the HTTP protocol for fetching the packages.

For more information on installing packages on your FreeBSD system, please refer to pkg-add(1)

Querying the local package database

In order to get information about installed packages you need to use the 'pkg info' command.

'pkg info' will query the local package database and display you information about the package you are intrested in.

To list all install/registered packages in the local database, you will use the following command:

# pkg info -a

For more information on querying the local package database, please refer to pkg-info(1) man page.

Using remote package repositories

The good thing about pkgng is that it is able to use remote package repositories.

A remote package repository contains a collection of packages which can be fetched, searched and installed into your systems.

The other good thing of pkgng is that it is able to work with multiple remote repositories, so you can actually fetch, search and install from multiple locations!

NOTE: Multple remote repositories are currently considered experimental.
      Currently multiple remote repositories can be used to fetch, search and
      install packages from. Upgrading from multiple repositories will be available
      in the next releases of pkgng. For now upgrading can only be done from
      a single remote package repository.

In order to use a remote repository you need to define the PACKAGESITE environment variable, so that it points to a remote location, which contains packages that can be installed by pkgng.

PACKAGESITE can also be set in the /etc/pkg.conf configuration file.

If the PACKAGESITE environment variable (or option in /etc/pkg.conf) is not defined then pkgng will work in multiple repositories mode, using the repositories which are defined in the /etc/pkg/repositories file.

In order to work with a single remote package repository, you would define PACKAGESITE to your remote server with packages, like for example (or use /etc/pkg.conf to set it there):

TCSH users:


SH users:


For multiple remote repositories the PACKAGESITE variable needs NOT to be defined and the remote package repositories should be definend in the /etc/pkg/repositories file.

A remote package repository in the /etc/pkg/repositories file uses the following format:

repo-name = url

The file format is the same as described in pkg.conf(5).

Example remote repository definition might look like this:

# dnaeon's repo of i386 packages
dnaeon-i386   =

# dnaeon's repo of amd64 packages
dnaeon-amd64  =

Please check the included sample 'repositories' file for example definitions of remote packages repositories and pkg.conf(5) for the file format of the file.

Updating remote repositories

The first thing to do when working with remote repositories is to update from them.

Updating remote repositories is done by the 'pkg update' command.

If PACKAGESITE environment variable is defined to point to a remote package repository then only this repository will be updated. Otherwise all remote repositories defined in the /etc/pkg/repositories file will be updated.

So, to update your remote repositories, you would execute this command:

# pkg update

For more information on the remote repositories, please refer to pkg-update(1).

Searching in remote package repositories

You can search in the remote package repositories using the 'pkg search' command.

In order to search in multiple package repositories the enviornment variable PACKAGESITE should NOT be defined, in which case 'pkg search' will query the remote package databases found in the /etc/pkg/repositories file.

An example search for a package could be done like this:

# pkg search -x apache

For more information on the repositories search, please refer to pkg-search(1)

Installing from remote repositories

In order to install a package from a remote repository you need to set the PACKAGESITE environment variable to point to the remote server.

If PACKAGESITE is not defined then the installation process will use multiple repositories as defined in the /etc/pkg/repositories file.

During installation from multiple repositories the first repository that is found to has the package is the first one that pkgng will use during the installation. If that repository is not accessible for some reason, then the next repository which contains the package is the one that is tried.

The process continues until the package is fetched and installed, or all remote repositories fail to fetch the package.

Remote installations of packages using pkgng are done by the 'pkg install' command.

Here's an example installation of few packages:

# pkg install www/apache22
# pkg install zsh
# pkg install perl-5.12.4

Or you could also install the packages using only one command, like this:

# pkg install www/apache22 zsh perl-5.12.4

For more information on the remote package installs, please refer to pkg-install(1)

Backing up your package database

It is a good idea that you backup your local package database on regular basis.

In order to backup the local package database, you should use the 'pkg backup' command.

# pkg backup -d /path/to/pkgng-backup.dump

The above command will create a compressed tar archive file of your local package database in /path/to/pkgng-backup.dump.txz

For more information on backing up your local package database, please refer to pkg-backup(1)

Creating a package repository

You can also use pkgng, so that you create a package repository.

In order to create a package repository you need to use the 'pkg create' command.

Here's an example that will create a repository of all your currently installed packages:

# cd /path/with/enough/space
# pkg create -a
# pkg repo . 

The above commands will create a repository of all packages on your system.

Now you can share your repo with other people by letting them know of your repository :)

Additional resources

In order to get in contact with us, you can find us in the #pkgng@FreeNode IRC channel.

If you hit a bug when using pkgng, you can always submit an issue in the pkgng issue tracker.