Skip to main content.

The basics of pkgsrc

2014-05-21

Live demo in BSD Now Episode 038 | Originally written by TJ for bsdnow.tv | Last updated: 2014/05/21

NOTE: the author/maintainer of the tutorial(s) is no longer with the show, so the information below may be outdated or incorrect.

Way back in 1997, NetBSD forked the FreeBSD ports system to create their own project. It was to be called pkgsrc, or "package source." In the NetBSD tradition, portability was a major goal. This tutorial is being done on a FreeBSD system. Today, pkgsrc can be used on a large number of platforms. It offers both binary packages and a way to compile software from source. We're mainly going to be demonstrating how to do it by source, since binary packages may not be as up to date or even available for all platforms. As of the time we do this tutorial, binary packages are not cryptographically signed either. Getting pkgsrc over CVS is probably the most secure method right now. You can also fetch it over FTP and untar it if you want to. We'll start by checking out the pkgsrc tree via CVS and running the bootstrap command.

# cd /usr
# cvs -q -z2 -d anoncvs@anoncvs.netbsd.org:/cvsroot checkout -P pkgsrc
# cd pkgsrc/bootstrap
# ./bootstrap

You can also append the "--unprivileged" flag to the bootstrap script to run as a non-root user. This will use ~/pkg/ instead of /usr/pkg as the prefix for binaries, config files and metadata information. To update your pkgsrc tree later on, run the following:

# cd /usr/pkgsrc
# cvs update -dP

Read and follow the directions printed afterwards. Once it finishes building the initial stuff, we can start installing the software we want. A good site to easily search pkgsrc is pkgsrc.se.

# vi ~/.cvsrc

The official pkgsrc guide recommends the following options in your ~/.cvsrc

cvs -q -z2
checkout -P
update -dP
diff -upN
rdiff -u
release -d

You will need to add "/usr/pkg/bin:/usr/pkg/sbin" to the beginning of your $PATH variable. This will vary greatly depending on what shell you're using. On FreeBSD, with csh, this can be temporarily done like so:

# setenv PATH /usr/pkg/bin:/usr/pkg/sbin:$PATH

But it will not persist, so please add it to your /etc/login.conf or whatever file your shell sources. Now let's install tmux for our example. Note that we use "bmake" instead of "make" here.

# cd /usr/pkgsrc/misc/tmux
# bmake install clean clean-depends

Even with just a simple program like tmux, you may quickly find yourself with lots of other things installed because of dependencies. On my test system, tmux pulled in all of this:

# pkg_info

bootstrap-mk-files-20140314 *.mk files for the bootstrap bmake utility
bmake-20140314      Portable (autoconf) version of NetBSD 'make' utility
pkg_install-20130902nb1 Package management and administration tools for pkgsrc
digest-20121220     Message digest wrapper utility
nbpatch-20100124    Patch files using diff output
libtool-base-2.4.2nb6 Generic shared library support script (the script itself)
gmake-4.0           GNU version of 'make' utility
libiconv-1.14nb2    Character set conversion library
gettext-lib-0.18.3.2 Internationalized Message Handling Library (libintl)
gettext-tools-0.18.3.2 Tools for providing messages in different languages
gtar-base-1.27.1nb1 The GNU tape archiver with remote magnetic tape support
perl-5.18.2nb1      Practical Extraction and Report Language
p5-Perl4-CoreLibs-0.003nb2 Libraries historically supplied with Perl 4
openssl-1.0.1g      Secure Socket Layer and cryptographic library
libevent-2.0.21nb3  Asynchronous event notification library
tmux-1.9a           BSD-licensed terminal multiplexer (GNU Screen alternative)

Check where it's actually installed with:

# which tmux

/usr/pkg/bin/tmux

If you'd like to remove something installed via pkgsrc, it's a very familiar command.

# pkg_delete tmux

There's also a command to check if any of your packages have known security vulnerabilities.

# pkg_admin fetch-pkg-vulnerabilities
# pkg_admin audit

To check if any of your packages are outdated, you should install the "lintpkgsrc" tool.

# cd /usr/pkgsrc/pkgtools/lintpkgsrc
# bmake install clean clean-depends

After updating your tree via CVS, check if anything needs to be upgraded like so:

# lintpkgsrc -i

Scan Makefiles: ..........

If there's an upgrade needed, change to that package's directory in /usr/pkgsrc and run

# bmake update

to get the newest version available in the tree. There are lots of configuration options for pkgsrc that you may be interested in. Specifically, some packages have different options they can be built with.

# cd /usr/pkgsrc/net/tor
# bmake show-options

Any of the following general options may be selected:
threads  Enable threads support.

These options are enabled by default:
    threads

These options are currently enabled:
    threads

You can select which build options to use by setting PKG_DEFAULT_OPTIONS
or PKG_OPTIONS.tor.

To set an option, you'll need to edit mk.conf and set what you want and don't want.

# vi /etc/mk.conf

PKG_DEFAULT_OPTIONS=  -threads

If you're unsure, just go with the defaults and you'll probably be fine. Be sure to check the FAQ and official documentation for everything else.

Latest News

New announcement

2017-05-25

Hi, Mr. Dexter. Also, we understand that Brad Davis thinks there should be more real news....

Two Year Anniversary

2015-08-08

We're quickly approaching our two-year anniversary, which will be on episode 105. To celebrate, we've created a unique t-shirt design, available for purchase until the end of August. Shirts will be shipped out around September 1st. Most of the proceeds will support the show, and specifically allow us to buy...

New discussion segment

2015-01-17

We're thinking about adding a new segment to the show where we discuss a topic that the listeners suggest. It's meant to be informative like a tutorial, but more of a "free discussion" format. If you have any subjects you want us to explore, or even just a good name...

How did you get into BSD?

2014-11-26

We've got a fun idea for the holidays this year: just like we ask during the interviews, we want to hear how all the viewers and listeners first got into BSD. Email us your story, either written or a video version, and we'll read and play some of them for...


Episode 220: Opening ZFS in 2017

2017-11-15

Direct Download:HD VideoMP3 AudioTorrent This episode was brought to you by Headlines The First PS4 Kernel Exploit: Adieu The First PS4 Kernel Exploit: Adieu Plenty of time has passed since we first demonstrated Linux running on the PS4. Now we will step back a bit and explain how we managed to jump...

Episode 219: We love the ARC

2017-11-08

Direct Download:HD VideoMP3 AudioTorrent This episode was brought to you by Headlines Papers We Love: ARC: A Self-Tuning, Low Overhead Replacement Cache Ever wondered how the ZFS ARC (Adaptive Replacement Cache) works? How about if Bryan Cantrill presented the original paper on its design? Today is that day. Slides It starts by looking back at a fundamental paper...

Episode 218: A KRACK in the WiFi

2017-11-01

Direct Download:HD VideoMP3 AudioTorrent This episode was brought to you by Headlines FreeBSD 10.4-RELEASE Available FreeBSD 10.4-RELEASE is out. The FreeBSD Project dedicates the FreeBSD 10.4-RELEASE to the memory of Andrey A. Chernov. Some of the highlights: 10.4-RELEASE is the first FreeBSD release to feature full support for eMMC storage, including eMMC partitions, TRIM...

Episode 217: Your questions, part II

2017-10-25

Direct Download:HD VideoMP3 AudioTorrent This episode was brought to you by Headlines OpenBSD 6.2 Released OpenBSD continues their six month release cadence with the release of 6.2, the 44th release On a disappointing note, the song for 6.2 will not be released until December Highlights: Improved hardware support on modern platforms including ARM64/ARMv7 and octeon,...