Installing Joyent’s pkgsrc package manager on OS X

As part of working with open source software on OS X, it’s often convenient to use a package manager to install open source packages. Good package managers are useful because they handle downloading the open source software you want, make sure that any related software dependencies get handled, and make it easy to keep the software you installed up to date.

That last point was important to me because Homebrew doesn’t do that. Instead, Homebrew installs software with the ownership set to be the user who ran the installation command.

That characteristic of Homebrew has always made me crazy, but I freely admit that’s my own personal peeve. As with many things, I’m not going to tell folks what package manager to use if their choice is working well for them.

To aid with the installation of pkgsrc on OS X, I’ve written a script. For more details, see below the jump.

The script below will download an OS-appropriate gzipped tar file from Joyent and install pkgsrc using the bootstrap installer stored inside the downloaded tar file.

Update 8-27-2015:pkgsrc has changed its directory location from /usr/pkg to /opt/pkg. This post has been updated to reference the new location.

Renames the downloaded tar file to pkgsrc.tar.gz and stores it in /tmp.

Installs pkgsrc into /opt/pkg using the bootstrap installer.

Updates pkgsrc with the latest package info.

After installation, removes the downloaded pkgsrc.tar.gz tar file from /tmp.

Post-installation

Once installed, the pkgsrc binaries are located inside of /opt/pkg. /opt/pkg is not automatically added to the list of places that Terminal will search for commands, so you may wish to add the following entries to your account’s .bash_profile file or your Mac’s /etc/profile file:

PATH=/opt/pkg/sbin:/opt/pkg/bin:$PATH

MANPATH=/opt/pkg/man:$MANPATH

If you want to set these variables for only your account, please run the following commands:

I was using pkgsrc and to be honest, I kind of prefer Macports at this point. Considering the pkgsrc is the standard repo and package manager for NetBSD, it is more *nix than MacPorts. But I tried to install a couple of packages yesterday using pkgsrc and both failed. The packages are well known ones like Finch and kdenlive.