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.
The ones that I’ve worked with in the past have been the following:
pkgsrc has the following strengths:
- Easy to install
- Works on multiple Unix-based platforms
- Installs its software all within one dedicated location (/opt/pkg)
- Does not require the creation of dedicated local user accounts
- Installs software with root privileges
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.
How the script works:
- Uses curl to download an OS-appropriate gzipped tar file containing the latest pkgsrc bootstrap installer from http://pkgsrc.joyent.com.
- 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.
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:
If you want to set these variables for only your account, please run the following commands:
echo "export PATH=/opt/pkg/sbin:/opt/pkg/bin:$PATH" >> $HOME/.bash_profile
echo "export MANPATH=/opt/pkg/man:$MANPATH" >> $HOME/.bash_profile
If you want to set these variables for all users on your Mac, please run the following commands instead with root privileges:
echo "export PATH=/opt/pkg/sbin:/opt/pkg/bin:$PATH" >> /etc/profile
echo "export MANPATH=/opt/pkg/man:$MANPATH" >> /etc/profile
After that, please close and re-open your Terminal window. That will allow the new path settings to take effect.
I’ve posted the script to my GitHub repo at the following address:
This script is also available as a payload-free installer package, stored as a .zip file in the payload_free_installer directory.