• Stars
    star
    740
  • Rank 61,282 (Top 2 %)
  • Language
    C
  • License
    Other
  • Created over 13 years ago
  • Updated about 2 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Package management tool for FreeBSD. Help at #pkg on Libera Chat or [email protected]

pkg - a binary package manager for FreeBSD

Known to fully work on (official package manager):

  • FreeBSD
  • DragonflyBSD

Known to work on (has been ported to):

  • Linux
  • NetBSD/EdgeBSD
  • OSX

Table of Contents:

Cirrus CI: (Linux, OSX, FreeBSD): Build Status

libpkg

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

pkg package format

The pkg package format is a tar archive that may be raw or compressed using one of the following algorithms: gz, bzip2, zstd, or xz. The default compression algorithm is zstd.

The tar archive itself is composed in two types of elements:

  • the special files at the beginning of the archive, starting with a "+"
  • the data.

The metadata

pkg uses several files for metadata:

  • +COMPACT_MANIFEST
  • +MANIFEST
COMPACT_MANIFEST

This is a subset of the information included in the main MANIFEST, omitting the lists of files, checksums, directories and scripts. It contains the information used to build the repository catalogue.

MANIFEST

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

name: foo
version: 1.0
origin: category/foo
comment: this is foo package
arch: i386
www: http://www.foo.org
maintainer: [email protected]
prefix: /usr/local
licenselogic: or
licenses: [MIT, MPL]
flatsize: 482120
users: [USER1, USER2]
groups: [GROUP1, GROUP2]
options: { OPT1: off, OPT2: on }
desc: <<EOD
  This is the description
  Of foo
  
  A component of bar
EOD
categories: [bar, plop]
deps: {
  libiconv: {origin: converters/libiconv, version: 1.13.1_2};
  perl: {origin: lang/perl5.12, version: 5.12.4 };
}
files: {
  /usr/local/bin/foo: 'sha256sum',
  /usr/local/bin/i_am_a_link: 'sha256sum';
  /usr/local/share/foo-1.0/foo.txt: 'sha256sum;
}
directories: {
  /usr/local/share/foo-1.0 : 'y';
}
scripts: {
  post-install: <<EOD
    #!/bin/sh
    echo post-install
EOD
  pre-install: <<EOD
    #!/bin/sh
    echo pre-install
EOD
}

Valid scripts are:

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

Script MUST be in sh format. Nothing else will work. The shebang is not required.

When the manifest is read by pkg_create files and dirs can use an alternate format:

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

This allows overriding the users, groups and mode of files and directories during package creation. So, for example, this allows to creation of a package containing root-owned files without being packaged by the root user.

Local database

When a package is installed, it is registered in a SQLite database.

The SQLite database allow fast queries and ACID transactions. It also allows finding the reverse dependencies reliably without a needing the +REQUIRED_BY hack.

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

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

Installing 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 repository catalogues and download and install the package if it exists. Any dependencies will be downloaded and installed first.

This is possible because we have the dependency information in the catalogue of the remote repository.

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

Upgrading packages

pkg also supports upgrades of binary packages.

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

Deleting packages

pkg delete will remove a package, and (depending on the command line arguments) any other packages that depend on what you're trying to delete.

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

Installing pkg

There are three ways to install pkg: two for general day-to-day use, and the third if you want to help with pkg development.

Pkg bootstrap

All supported versions of FreeBSD now contain /usr/sbin/pkg a.k.a pkg(7). This is a small placeholder that has just the minimum functionality required to install the real pkg(8).

To use, simply run any pkg(8) command line. pkg(7) will intercept the command, and if you confirm that is your intention, download the pkg(8) tarball, install pkg(8) from it, bootstrap the local package database and then proceed to run the command you originally requested.

More recent versions of pkg(7) understand pkg -N as a test to see if pkg(8) is installed without triggering the installation, and conversely, pkg bootstrap[-f] to install pkg(8) (or force it to be reinstalled) without performing any other actions.

pkg in Ports

pkg-1.0 release was committed to the the ports tree on 30th August 2012, and a series of further releases are planned. To install the latest release version:

$ make -C /usr/ports/ports-mgmt/pkg install clean
$ echo "WITH_PKG=yes" >> /etc/make.conf

Building pkg using sources from Git [FreeBSD]

In order to build pkg from source, you will need to have Gnu autotools and some other tools installed.

# pkg install autoconf automake libtool pkgconf

The next thing to do is to get the pkg sources installed on your machine. You can grab a development snapshot of pkg from the pkg GitHub repository

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

% git clone https://github.com/freebsd/pkg

or

% git clone [email protected]:freebsd/pkg.git

Or you can take an already tagged release of pkg from the above web page as well. Just open your browser and download the release you want.

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

% cd pkg
% ./configure
% make
# make install

Now you should have the latest pkg installed on your system. Note that this build and install procedure does not update the local package database at all, so you will get some odd effects due to the packaging system being misled into thinking an older version of pkg is installed.

Note: if you're running anything other than FreeBSD or DragonFly, you will need to do some porting work. The pkg(8) codebase should be reasonably portable onto anything with a c99 compiler, POSIX compliant system and capable of running Gnu autotools. However, various places in the pkg(8) code make assumptions about OS specific behaviour. If you do try anything like this, we'd be very interested to hear how you get on.

A quick usage introduction to pkg

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

Getting help on the commands usage

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

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

# pkg help
# pkg help <command>

Querying the local package database

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

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

To list all install/registered packages in the local database, use this command:

# pkg info -a

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

Installing packages

Packages are installed either from a repository, from the results of a local compilation of software via the ports or from a pkg tarball independently obtained from some other source.

A repository is a collection of packages which have been gathered together, had a catalogue created and then published, typically by exposing the repository via HTTP or some other networking protocol. You can also publish a repository from a local or NFS mounted filesystem (using file:// style URLs) or via SSH (using ssh:// URLs.)

Working with a remote package repository

While pkg(8) can deal with individual package tarballs, the real power comes from the use of repositories, which publish a 'catalogue' of meta-data about the packages they contain.

You can configure pkg(8) to use one or several repositories. Supported versions of FreeBSD now contain a default configuration out of the box: /etc/pkg/FreeBSD.conf which is setup to install packages from the official package repositories.

To add additional repositories, create a per-repository configuration file in /usr/local/etc/pkg/repos -- it doesn't matter what the filename is other than it must match '*.conf' and you should add a 'priority' setting indicating the preference order. This is just an integer, where higher values indicate the more preferred repositories. Priority defaults to 0 unless explicitly stated. This is the value for the default /etc/pkg/FreeBSD.conf

To disable the default FreeBSD.conf, create a file /usr/local/etc/pkg/repos/FreeBSD.conf with the contents:

FreeBSD: { enabled: no }

To check quickly what repositories you have configured, run pkg -vv.

See pkg.conf(5) for details of the format of pkg.conf and the per-repository repo.conf files. See pkg-repository(5) for more details about package repositories and how to work with them.

Note that the old style of setting PACKAGESITE in pkg.conf is no-longer supported. Setting PACKAGESITE in the environment has meaning for the pkg(7) shim, but is ignored by pkg(8).

Updating from remote repositories

Then fetch the repository catalogues using the command:

# pkg update

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

This will fetch the remote package database to your local system. Now in order to install packages from the remote repository, you can use the pkg install command:

# pkg install zsh cfengine3

Working with multiple repositories

If you have more than one repository defined, then you probably want to install some packages from a specific repository, but allow others to be obtained from whatever repository has them available.

You can install a package from a specific repository:

	# pkg install -r myrepo zsh

where myrepo is one of the tags shown in the pkg -vv output. pkg(8) will automatically create an annotation showing which repository a package came from, similarly to the effect of running:

    # pkg annotate -A pkgname repository myrepo

pkg(8) will attempt to use the same repository for any updates to this package, even if there are more recent versions available from other repositories. This is usually the desired behaviour. Otherwise see the documentation for CONSERVATIVE_UPGRADE in pkg.conf(5).

Searching in remote package repositories

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

If you have multiple repositories configured, pkg search will return results from searching each of them. Use the -r reponame option to confine your search to a specific repository.

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

pkg(8) will install a package from the highest priority repository that contains the package and that allows the solver to satisfy the package dependencies. This may entail reinstalling existing packages from a different repository.

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

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

Here's an example installation of few packages:

# pkg install www/apache22
# pkg install zsh
# pkg install perl5-5.18.2_4

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

# pkg install www/apache22 zsh perl5-5.18.2_4

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

Creating a package repository

You can also use pkg, 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

To contact us, you can find us in the #pkg channel on Libera Chat IRC Network.

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

More Repositories

1

freebsd-src

The FreeBSD src tree publish-only repository. Experimenting with 'simple' pull requests....
C
7,783
star
2

freebsd-ports

FreeBSD ports tree (read-only mirror)
Makefile
966
star
3

crochet

Build FreeBSD images for RaspberryPi, BeagleBone, PandaBoard, and others.
Shell
611
star
4

poudriere

Port/Package build and test system
Shell
384
star
5

freebsd-doc

FreeBSD doc tree (read-only mirror)
HTML
308
star
6

openlaunchd

A launchd(8) port for non-Darwin systems
C
260
star
7

drm-kmod

drm driver for FreeBSD
C
154
star
8

kyua

Testing framework for infrastructure software
C++
147
star
9

freebsd-wifi-build

freebsd-wifi-build
Shell
141
star
10

atf

Libraries to write tests in C, C++ and shell
C
133
star
11

freebsd-ci

FreeBSD Continuous Integration (CI)
Shell
115
star
12

freebsd-papers

The FreeBSD Papers, Slides, and Video Collection
HTML
91
star
13

portmaster

FreeBSD port management script without external databases or languages
Shell
79
star
14

freebsd-quarterly

FreeBSD quarterly reports
Perl
58
star
15

freebsd-ports-kde

FreeBSD KDE development repo
Makefile
53
star
16

portupgrade

FreeBSD ports and packages management app
Ruby
41
star
17

pytoport

Generate FreeBSD Ports from Python modules on PyPI
Python
30
star
18

freebsd-ports-gnome

FreeBSD GNOME development repo
30
star
19

meetings

Notes from meetings of various FreeBSD-related groups.
29
star
20

fcp

The FreeBSD Community Proposal Repository
25
star
21

lutok

Lightweight C++ API for Lua
C++
24
star
22

redports

Redports is a continuous integration platform for FreeBSD ports.
PHP
22
star
23

drm-kmod-firmware

KMS firmware components for graphics/kms-firmware port
Makefile
22
star
24

libdevq

Generic Device Query and Monitor interface
C
20
star
25

bugzilla

Bugzilla
Perl
20
star
26

portscout

A tool which looks for new versions of software in the FreeBSD ports tree
Perl
19
star
27

iocage

A FreeBSD jail manager
Python
19
star
28

pkg-plugins

Plugins for pkg
C
18
star
29

chromium

FreeBSD Chromium Port
C++
18
star
30

freebsd-ports-libreoffice

Staging area of LibreOffice port on FreeBSD
Makefile
17
star
31

git_conv

Scripts used for the svn to git conversion of the FreeBSD repositories
C++
12
star
32

pkg_install

pkg_install wrapper on top of libpkg(8)
C
11
star
33

freebsd-update-build

Shell
11
star
34

freebsd-ports-haskell

8
star
35

jenkins-config

Backup of config files used by jenkins.freebsd.org
8
star
36

redports-1

Redports is a continuous integration platform for FreeBSD ports. It helps ports developers to test changes in clean environments and provides a nice web-based user interface.
JavaScript
8
star
37

calendar-data

4.4BSD Calendar Program Data Files
7
star
38

kyua-fork

Testing framework for infrastructure software
C++
7
star
39

timed

Time Daemon
C
5
star
40

freebsd-doc-translate

Repository used for translating documents of FreeBSD, now using Weblate.
5
star
41

core.10-public-docs

Core.10 Public Documents
5
star
42

atf-fork

Libraries to write tests in C, C++ and shell
C
5
star
43

freebsd-update-mirror

Shell
4
star
44

freebsd-legacy

FreeBSD src tree (legacy mirror of old hashes DO NOT USE)
C
4
star
45

opie

C
4
star
46

docng

Next Generation of FreeBSD Docs
HTML
4
star
47

rpi3-psci-monitor

Assembly
4
star
48

ctm

C
3
star
49

pkg-appstream

C
3
star
50

portsnap-build

Portsnap ports tree update build infrastructure
Shell
3
star
51

mfctracker

Code source behind https://mfc.freebsd.org
Python
3
star
52

freebsd-doc-legacy

FreeBSD doc tree (legacy mirror of old hashes DO NOT USE)
HTML
2
star
53

cpdup

Copy of https://github.com/DragonflyBSD/cpdup with FreeBSD specific features
C
2
star
54

freebsd-ports-legacy

FreeBSD ports tree (legacy mirror of old hashes DO NOT USE)
2
star
55

virtual_oss

Virtual OSSv4 compatible digital audio workstation daemon
C
1
star
56

lutok-fork

Lightweight C++ API for Lua
C++
1
star
57

wireless

1
star