• Sales: (866) 518-YARD

Homebrew: OS X’s Missing Package Manager

By Andre Arko | February 2nd, 2010 at 10:02AM

Managing software packages on Unix has always been, to put it politely, a giant pain, and most Linux distributions are built around the different ways we’ve all been trying to alleviate that pain. In this post, I’ll walk you through Homebrew, a fantastic new option for package management made simple.

Pre-Homebrew, there were various attempts to create effective package managers for OS X. The two most popular efforts were Fink and MacPorts, but they each had their frustrations. In both cases, creating packages or portfiles was still complex and difficult.

Max Howell‘s done a great job with Homebrew; it’s easy to edit, and creating new packages is a breeze. Let’s dig in!

What Does It Do?

The pitch is simple: Homebrew alleviates the drudgery and repetition of downloading and installing Unix software packages on OS X. If you’re sick of ./configure && make && make install, Homebrew can help.

Why Homebrew?

As previously mentioned, OS X already has two package managers: Fink and MacPorts. If one of those is working for you, great. But if you’ve been frustrated by them in the past, I strongly suggest you give Homebrew a try. It’s easy to create and edit formulae, and even to edit Homebrew itself, since the core is just a few hundred lines of Ruby code.

It doesn’t impose external structure on you: the default is to install it to /usr/local, but you can install it anywhere. Inside your Homebrew directory, software is installed in subdirectories inside Homebrew’s cellar, like Cellar/git/1.6.5.4/. After installation, Homebrew symlinks the software into the regular Unix directories. If you want to hand-install a package or version that isn’t officially part of Homebrew yet, it can happily coexist in the same location.

That’s usually not necessary, though, since formulae can install directly from version control. If a package has a public git, svn, cvs, or mercurial repository, you can install the latest development version as often as you’d like with a simple brew install.

Installing packages is faster, too, because Homebrew also works hard to avoid package duplication. No more installing yet another version of Perl as a package dependency when you already have a working install of Perl built into OS X. Best of all, Homebrew has a basic philosophy that you shouldn’t have to use sudo to install or manage software on your computer.

Sounds Pretty Great… How Do I Get It?

The first (and only) dependency that Homebrew has is the OS X Developer Tools, which are on the OS X installer disc, and available from Apple as a free download.

Unless you have a reason not to, the easiest place to install Homebrew is in /usr/local. You can do that in just a few steps on the command line:

# Take ownership of /usr/local so you don't have to sudo
sudo chown -R `whoami` /usr/local
# Fix the permissions on your mysql installation, if you have one
sudo chown -R mysql:mysql /usr/local/mysql
# Download and install Homebrew from github
curl -L http://github.com/mxcl/homebrew/tarball/master | tar xz --strip 1 -C /usr/local

Once you’ve done that, you’re good to go! Assuming /usr/local/bin is in your PATH, feel free to try it out:

brew install wget
brew info git

The Homebrew wiki also has more about integrating with RubyGems, CPAN, and Python’s EasyInstall.

Keeping your copy of Homebrew up to date is easy, too:

brew install git
brew update

Once you have git installed, you can just run brew update any time you want to pull down the latest formulae.

Contributing

Creating a new formula is almost that easy. If Homebrew didn’t have a formula for wget, you could create one like this:

brew create http://ftp.gnu.org/gnu/wget/wget-1.12.tar.bz2

After you save your formula, you can test it out with brew install -vd wget, to enable verbose logging and debug mode. If you need help getting your formula working, there’s more documentation on the Homebrew wiki. You can also learn by example from already existing formula, like git or flac.

You can check out lots of example formulae, as well as the internals of Homebrew, by running brew edit. The code is pretty straightforward. If you have questions, or are interested in future plans, the contributors to Homebrew tend to hang out in the #machomebrew channel on Freenode.

Once you have a working new formula, it’s easy to create your own fork of Homebrew on GitHub to push your new formula to, by using the github gem:

git add .
git commit -m "Added a formula for wget"
gem install json github
github fork
git push <your github username> mastergitx

After pushing your change to GitHub, go to the Homebrew issue tracker and create a ticket with the subject “New formula: “. Assuming everything checks out, your formula will be added to the main Homebrew repository and available for everyone else to use.

Wrapping Up

Homebrew is a compelling alternative to MacPorts and Fink. The Homebrew core and all the formulae are written in Ruby, so it’s easy to add new packages or even new features. If you’re looking for more control over the Unix software you have installed on your Mac, or you’ve been frustrated by other package managers in the past, check it out. I think you’ll be happily surprised.

Share this post:
  • email
  • Digg
  • del.icio.us
  • Reddit
  • Slashdot
  • StumbleUpon
  • Technorati
  • Twitter
  • Google Bookmarks
  • Facebook
  • LinkedIn
Popularity: 58% |
Rate this post: 1 Star2 Stars3 Stars4 Stars5 Stars
Loading ... Loading ...

This website uses IntenseDebate comments, but they are not currently loaded because either your browser doesn't support JavaScript, or they didn't load fast enough.

23 Responses to “Homebrew: OS X’s Missing Package Manager”

  1. Anon. Anon. says:

    > # Take ownership of /usr/local so you don't have to sudo
    > sudo chown -R `whoami` /usr/local

    Wow, are you joking?

  2. Mike Arthur Mike Arthur says:

    There is nothing in /usr/local by default so I'm not sure what the problem is here?

    • Gene Gene says:

      "by default" in a clean OS X install maybe not. but I have Postgres there, Google App Engine installs stuff there, and a VPN client called Juniper – among other stuff. Changing /usr/local to be owned by a user is a massive kludge.

    • Duff Duff says:

      Uh… It's just a bad practice, plain and simple.

      My wife and I share a Mac. One account owning everything in /usr/local is a problem. I do other things that place other stuff in /usr/local. That will be messed up.

      It also encourages package builders to do break thing that Unix fixed in the mid-80's. I setup brew in my home directory and installed wget. Guess what? No symlink was created! Ever hear of environment variables?

  3. bryanl bryanl says:

    homebrew is great. one problem i've found is that it isn't very easy to see what is or isn't outdated.

  4. arathoward arathoward says:

    so they've re-invented gnu stow? http://www.gnu.org/software/stow/

    • Indirect Indirect says:

      Stow, in Ruby, on Github, actively soliciting contributions, specifically targeting OS X. Sounds like a pretty good re-invention to me.

  5. Love it. Im building my work computer from scratch today. Thanks to homebrew, it's easy and awesome.

    • Just to follow up on this – one issue I ran in to is homebrew doesn't have a built in way to build ruby 1.8.7. I ran into a few problems as a result of this. I'd recommend supplementing homebrew with RVM.

  6. Elk Elk says:

    I can't figure out why I'd use Homebrew instead of MacPorts and/or stow. The thing I look for in a package manager is a very large number of pre-configured, stable packages available in the repository. I never craft my own packages. If I have to install something from source, it gets installed in my home directory or somewhere else using stow.

    I'm a developer who uses ruby and git, too… Maybe I would think differently if I started with a Mac and then moved into *nix, instead of the other way around?

    • kevinelliott kevinelliott says:

      I agree with you, Elk, completely. I like the idea of my package manager being built with Ruby, but it's most definitely not a real need. MacPorts works just fine, and has lots of packages available! If Homebrew felt like a native Mac app, then that alone might be a real reason to switch to it. Otherwise, it's just another toy, that will probably fade since other more reliable ones exist (with larger communities to support it).

      • CpILL CpILL says:

        no no, macPorts doesn't give you much control. try rolling back from PHP5.3 and you'll know what I'm talking about. Also brew is more efficient with its compiling and doesn't pull down masses of junk EVERY TIME YOU INSTALL something. Its philosophy is better and thats what makes Macs stand out form the PC crowd to begin with.

        I think it has a future.

        • Hang on. If you're trying to implying that Macs are superior because they dont "pull down masses of junk every time you install something"… you're wrong there. Homebrew may not, but to be sure, the normal mac install procedure (installing via dmg, drag and dropping to "Applications") does… Think why your dmgs are so large, compared to your linux equivalent install. Every dmg pulls down its own set of libraries. Got firefox? You've got libsqlite3 in there. Got vlc? There's another libsqlite3 in there.

          /another nix guy here :)

  7. .jon .jon says:

    I am a long time MacPorts user and while I always preferred the Ports system to any other package-manager I absolutely hate the carelessness of the MacPorts. Whether it were problems I ran into due to the port maintainer disregarding the software developers recommendation or all the Python, Perl and whatever versions, they install along…

    The only reason I do not brew is because I have installed native ports of *ixish stuff and they have thrown a lot intu /usr/local/lib and I do not feel like deleting, breaking up my system.

    Another such effort, btw., is Rudix.org. Those packages install into /usr/local, are self-contained (statically linked), use the software, that comes with OS X (Python, etc.) and are being installed as PKG from within a DMG.

    • Indirect Indirect says:

      You can still use homebrew, though. You can install (most) homebrew packages even if homebrew isn't installed into /usr/local, and is just in ~/.homebrew or something. You can also simply put the homebrew files into /usr/local, and homebrew will happily co-exist with whatever you already have installed.

  8. Markus Arike Markus Arike says:

    You might consider warning people who may not know better that the shell command,

    sudo chown -R mysql:mysql /usr/local/mysql

    will make all their existing tables inaccessible. Anyway, thanks.

  9. [...] Q: Why not using Macports or fink ? A: 更新速度慢, 會沒事裝一些你不需要的東西, 系統最後相當不乾淨. 所以會改用 brew, 有關於 Mac 套件管理方面的 issue 可見 Engineyard 之前寫的 Homebrew 介紹文。 [...]

  10. Great article, it helped me figure out how to install a more recent version of a tarball. If you don't know what you're doing, like me, there is a bit of a disconnect between the "it's easy to create a new formula" deal and actually using it. Plus it doesn't always use a name you would expect for the formula. Like when installing sqlite3 it used sqlite3-amalgamation and I was at a loss till I tried figure out I had to save it in the cache, change the file and class names, and then install it. I guess I could have used the longer name but I wanted to update what was already there.

    Anyway thanks a lot, you really help a newbie out!