pkgsrc on Linux - Quickstart Guide [DEPRECATED]

WARNING This is an old and unmaintained post. It has been superseded by Essential pkgsrc - The Missing Mini Handbook. I highly encourage you to read the updated post. This post has not been removed so links from other sites don't break.

Do you want to try out pkgsrc on Linux? Here’s a quickstart guide (tested on Ubuntu 14.04). Of course, always refer to the pkgsrc guide for accurate information.

Get pkgsrc

Install prerequisities.

[user@host ~]$ sudo aptitude install build-essential libncurses-dev git

Create directory structure in your home directory.

[user@host ~]$ mkdir ~/opt

[user@host ~]$ cd ~/opt

You have two options for getting pkgsrc: (1) the official ways: by downloading a tar file and extracting it, or by using CVS; (2) by using git. The first way, by using a tar file, is described in the pkgsrc guide.

The second way, to use git, is also easy. Jörg Sonnenberger has created a GitHub repo that syncs with pkgsrc source.

Here we're using the master (trunk) branch. You can choose to use the latest stable branch instead. Refer to pkgsrc for more information.

[user@host ~/opt]$ git clone https://github.com/jsonn/pkgsrc.git

I think I would prefer using git.

Install pkgsrc

Install pkgsrc to your home directory under ~/pkg. By default it installs system-wide but I don't want to do that in this guide.

[user@host ~/opt]$ cd ~/opt/pkgsrc/bootstrap/

[user@host ~/opt/pkgsrc/bootstrap]$ export SH=/bin/bash

[user@host ~/opt/pkgsrc/bootstrap]$ ./bootstrap --unprivileged

Install pkg_* tools

Let's install some tools to manage packages.

[user@host ~/opt/pkgsrc/bootstrap] cd ~/opt/pkgsrc/pkgtools/pkg_install

[user@host ~/opt/pkgsrc/pkgtools/pkg_install] ~/pkg/bin/bmake install clean clean-depends

[user@host ~/opt/pkgsrc/pkgtools/pkg_install] cd ~/opt/pkgsrc/pkgtools/pkg_rolling-replace

[user@host ~/opt/pkgsrc/pkgtools/pkg_rolling-replace] ~/pkg/bin/bmake install clean clean-depends

[user@host ~/opt/pkgsrc/pkgtools/pkg_install] cd ~/opt/pkgsrc/pkgtools/pkg_chk

[user@host ~/opt/pkgsrc/pkgtools/pkg_chk] ~/pkg/bin/bmake install clean clean-depends

Add ~/pkg to PATH

You may want to add ~/pkg/bin and ~/pkg/sbin to your PATH.

[user@host ~]$ echo "export PATH=\$PATH:\$HOME/pkg/bin:\$HOME/pkg/sbin" >> ~/.bashrc

[user@host ~]$ source ~/.bashrc

Check for package vulnerabilities

[user@host ~] pkg_admin -K ~/pkg/var/db/pkg fetch-pkg-vulnerabilities

[user@host ~] pkg_admin audit

Search Package

Change to ~/opt/pksrc directory and use pkglocate to search for packages. For example, let's look for Bottle, a WSGI framework.

[user@host ~]$ cd ~/opt/pksrc

[user@host ~/opt/pksrc]$ ./pkglocate -i bottle

Install Package

Let’s install Bottle. Be prepared to wait a while because it'll pull in lots of dependencies that also need to be fetched, built, and installed.

Change to the directory containing the Bottle package and install it.

[user@host ~]$ cd ~/opt/pkgsrc/www/py-bottle

To install you have two options:

  • Compile from source and install directly
  • Create a package after compiling from source and install package

The first option is:

[user@host ~/opt/pkgsrc/www/py-bottle]$ bmake install clean clean-depends

The second option is:

[user@host ~/opt/pkgsrc/www/py-bottle]$ env USE_DESTDIR=yes bmake package clean clean-depends

[user@host ~/opt/pkgsrc/www/py-bottle]$ cd ~/opt/pkgsrc/packages/All

[user@host ~/opt/pkgsrc/packages/All]$ pkg_add bottle-0.12.7.tgz

Update Packages

Follow these steps when you want to update a single package, say Bottle.

[user@host ~]$ cd ~/opt/pkgsrc

Pull in latest changes to pkgsrc.

[user@host ~/opt/pkgsrc]$ git pull

Update All Outdated Packages

There are two ways: pkg_rolling-replace or pkg_chk. pkg_chk first uninstalls all packages that need to be updated so may be more unsafe. pkg_rolling-replace on the other hand also removes packages before installing them but is a safer version. Read more on how to upgrade packages.

pkg_rolling-replace

Add PKGSRC environment variable to ~/pkg/etc/mk.conf file. In the example below change /home/user/... to match your user.

PKGSRCDIR=              /home/user/opt/pkgsrc

List updates:

[user@host ~/opt/pkgsrc/]$ pkg_rolling-replace -u -n -v

Update packages:

[user@host ~/opt/pkgsrc/]$ pkg_rolling-replace -u -v

pkg_chk

List packages that need to be updated.

[user@host ~]$ pkg_chk -u -q

Update all outdated packages.

[user@host ~]$ pkg_chk -u -s

Update Single Package

Follow these steps when you want to update a single package, say Bottle.

Change to the directory containing the Bottle package and update it.

[user@host ~/opt/pkgsrc]$ cd ~/opt/pkgsrc/www/py-bottle

As with install you have two options: install directly or create a package first.

To install directly:

[user@host ~/opt/pkgsrc/www/py-bottle]$ bmake update clean clean-depends

To create a package first:

[user@host ~/opt/pkgsrc/www/py-bottle]$ env USE_DESTDIR=yes bmake package clean clean-depends

[user@host ~/opt/pkgsrc/www/py-bottle]$ cd ~/opt/pkgsrc/packages/All

[user@host ~/opt/pkgsrc/packages/All]$ pkg_add -u bottle-0.12.7.tgz

List Installed Packages

To get a list of all installed packages:

[user@host ~]$ pkg_info -Q PKGPATH -a

Delete Package

Use pkg_delete to remove a package.

[user@host ~]$ pkg_delete bottle

You can uninstall a package and all its dependencies that are not needed by any other package.

[user@host ~]$ pkg_delete -R bottle