Sunday, June 26, 2011

pkgsrc alogside homebrew

UPDATE [07/02/12] : This post has been completely obsoleted by the content in a newer post about setting up a Mac more generally. Installing Pkgsrc & Homebrew are covered in detail with updates that address homebrew's change to prevent installing as a user not in the admin group as well as using the git mirror for pkgsrc. I'll keep the content here for historical purposes but you should really follow what's in the new post: Fresh Mac Setup

I live on the unix command line. Many mac users gasp in horror when the see me at a prompt that they think is "DOS" or something. They think I've broken my Macbook Pro and this is the way I 'fix' it. When I try to explain to them that I'm more at home with a keyboard and a blinking cursor than with a mouse/touchpad inside a GUI they just don't get it. On the other side you have people who say "well if you like the command line so much why not just use Ubuntu". The short answer is: with very few exceptions (Slackware, Gentoo and Funtoo), every Linux distribution I've used makes me want to slap the developers and stab the users/zealots who peddle that crap. <FlameOff> The Linux kernel is nothing less than a coup, to be admired for all of the hours of sheer genius that resulted in the very rich functionality it holds. Why no Linux distributions are as equally inspiring a mystery. </FlameOff> Save your shouts of protest, I've used Redhat (before RHEL and Fedora after) , LinuxMint (hell I run one of the mirrors), Trisquel, Debian, YellowDog, Ubuntu, Mandrake, Mandriva, Yggdrasil, Suse and they all leave me running back to a good old sensible BSD.

While I've never been much of a fan of NetBSD in particular, one would have to concede that they did a really good thing by making pkgsrc so flexible. The fact that runs on every modern Unix(-like) system is just plain awesome. Since OS X is Unix, pkgsrc just fits. I've used fink (bleh), macports (nice but much less flexible) and Homebrew (great but very incomplete). In fact I still use Homebrew as my defualt solution for unix tools. The problem is that they are pretty restrictive as to what they will accept and the formulae tend to be pretty slim on options. So when I need more flexibility in what available I reach for pkgsrc.

One of the pluses with homebrew is that it expects to be installed in /usr/local and to have all of it's packages installed and linked under /usr/local/. The kicker is that /usr/local should be set to permissions that allow an unprivileged user manage and install applications. All the others default to installing things as root. My setup:

  1. Make sure Xcode is installed
  2. As an admin user :
    1. sudo mkdir -p /usr/local/src
    2. sudo chown -R [USERID]:staff /usr/local/ #replace [USERID] with your normal user id
    3. sudo chmod 775 /usr/local/* 
  3. As normal (unprivileged) user:
    1. Install homebrew:
      1. ruby -e "$(curl -fsSL"
    2. Install git:
      1. brew install git
    3. update brew formulae (just incase):
      1. brew update
    4. Install pkgsrc:
      1. cd /usr/local/
      2. curl | tar xzvf -
      3. cd pkgsrc/bootstrap
      4. ./bootstrap --pkgdbdir /usr/local/var/db/pkg --unprivileged --prefix /usr/local/pkg
At  step 3.4.2 we use the tarball path given at This path will likely change in the near future. So get the latest copy for your purposes.

In 3.4.4 we setup pkgsrc to install to /usr/local/pkg so more of our binaries will be in /usr/local/pkg/bin or /usr/local/pkg/sbin. It's important to modify your PATH and MANPATH variables. You generally want pkgsrc apps to be found AFTER their homebrew counterparts. If you don't know what those last to sentences mean, please stop before you break your computer. 

In the end you'll have a working pkgsrc install alongside your homebrew install. You can install packages from either system without needing to escalate to an administrative user.

No comments:

Post a Comment