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:
All have their good points and bad points, but my colleague Tom Bridge pointed me in the direction of Joyent’s pkgsrc and this one may be my go-to going forward.
pkgsrc has the following strengths:
- Easy to install
- Works on multiple Unix-based platforms
- Installs its software all within one dedicated location (/usr/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.
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 /usr/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 /usr/pkg. /usr/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=/usr/pkg/sbin:/usr/pkg/bin:$PATH
MANPATH=/usr/pkg/man:$MANPATH
If you want to set these variables for only your account, please run the following commands:
echo "export PATH=/usr/pkg/sbin:/usr/pkg/bin:$PATH" >> $HOME/.bash_profile
echo "export MANPATH=/usr/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=/usr/pkg/sbin:/usr/pkg/bin:$PATH" >> /etc/profile
echo "export MANPATH=/usr/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:
https://github.com/rtrouton/rtrouton_scripts/tree/master/rtrouton_scripts/install_joyent_pkgsrc
This script is also available as a payload-free installer package, stored as a .zip file in the payload_free_installer directory.