Home > Mac OS X, Scripting, Unix > Installing Joyent’s pkgsrc package manager on OS X

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:

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:

  1. Easy to install
  2. Works on multiple Unix-based platforms
  3. Installs its software all within one dedicated location (/opt/pkg)
  4. Does not require the creation of dedicated local user accounts
  5. 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:

  1. Uses curl to download an OS-appropriate gzipped tar file containing the latest pkgsrc bootstrap installer from http://pkgsrc.joyent.com.
  2. Renames the downloaded tar file to pkgsrc.tar.gz and stores it in /tmp.
  3. Installs pkgsrc into /opt/pkg using the bootstrap installer.
  4. Updates pkgsrc with the latest package info.
  5. 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.

Categories: Mac OS X, Scripting, Unix
  1. April 24, 2015 at 7:00 pm

    A post is not complete unless there is a link to an AutoPKG recipe. 😉

    regex: http://pkgsrc.joyent.com/packages/Darwin/bootstrap/bootstrap-\d{4}[Q]\d{1}-x86_64.tar.gz\n

  2. July 11, 2018 at 10:42 am

    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.

  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: