Homebrew package management for Mac OS

Dec 30 2009 by Michael Biven

Update : After I stopped using Homebrew I pulled post this until I had a chance to edit it and then my time was focused on another project. You can view the updated post here.

There have been several different package management tools that have appeared for Mac OS - Fink, MacPorts and now Homebrew. Created by Max Howell former developer at Last.fm (led the work on all of their desktop and mobile software) it has become one of the most popular projects forked on GitHub.

Like the others it's a simple method of installing open source software, but it is built to keep them in line with software that is already installed either by yourself or the default stuff in Mac OS. This is due to it giving you control over where it's installed,a loose policy of not duplicating what is in CPAN, Python Easy_install, pip or Ruby gems and that homebrew allows you to see what is going on in the background during the install which hopefully encourages you to make changes yourself.

Requirements

If you plan on creating your own fork to add your own formulas you should install the following:

Where To Install

One advantage of installing it in /usr/local is that it is already in your PATH which lets any future software that you install work with stuff installed by homebrew and for homebrew to work with anything you already have there. You can install homebrew anywhere, but it make sense to have it at /usr/local for the reasons stated above.

Download And Install

Grab the latest copy from Max's repository on GitHub and place them in /usr/local.

curl -L http://github.com/mxcl/homebrew/tarball/master | tar xz --strip 1 -C /usr/local

If you want to create your own fork go to homebrew's GitHub page and click "Fork". Now to install at /usr/local run the commands below, but change YOURGITHUBNAME to your github account name.

cd /usr/local
git init
git remote add origin git://github.com/YOURGITHUBNAME/homebrew.git
git pull origin master

Starting Off

Now homebrew is installed at /usr/local with the following directories:

/usr/local/Library/Contributions - contributions
/usr/local/Library/Formula - the formulas
/usr/local/Library/Homebrew - files for homebrew itself
/usr/local/Cellar - placeholder for items installed by homebrew 
(they get symlinked to /usr/local/bin, /usr/local/lib etc)

Two commands you should start off with is search and info.

search - search to see if there is a formula in the local copy of homebrew, remember people are adding formulas and they will not find themselves added to Max's copy immediately. So check the tickets to see if someone has already created what you are looking for.

brew search apache

info - shows the version of the software that the formula installs, the homepage for the project, dependencies, if it is already installed shows its location and then any caveats (quick and dirty readme) that might be in the formula.

brew info apachetop

Creating Your Own Formula

To create your own formula it's as simple as:

brew create link-to-download

This will open it up in your default text editor and you can either decide to maintain it and contribute back to everyone else or maintain your own list of formula's that meet your needs.

For example say you would like to give drizzle a try (I already have created formulas for both libdrizzle and drizzle).

Drizzle has the following requirements:

Most of these are probably already installed except for libdrizzle and protobufs. So we will install protobuf which already has a formula and create one for both libdrizzle and drizzle.

Installing A Formula

First thing is to use the existing formula to install protobuf. We do this by running the brew install command.

brew install protobuf -v

If you get an error similar to:

"libprotobuf FATAL google/protobuf/descriptor.pb.cc:84] CHECK failed: file != NULL:
make[1]: *** [unittest_proto_middleman] Abort trap
make: *** [install-recursive] Error 1
Error: #"

Either edit the formula to change the install to this:

def install
            ENV.gcc_4_2
            system "./configure", "--prefix=#{prefix}"
            system "make"
            system "make install"
            end

Or try the copy of protobuf.rb from my fork.

Now we will create the formula for libdrizzle. The command below will open up the formula in your text editor and you will need to grab the URL for the projects homepage, the md5 checksum and add them to the formula. You can compare what you have with the formula I added.

brew create http://launchpad.net/libdrizzle/trunk/0.6/+download/libdrizzle-0.6.tar.gz

Next step is to install libdrizzle.

brew install libdrizzle -v

And now create the formula for drizzle just like we did for libdrizzle.

brew create http://launchpad.net/drizzle/trunk/bell/+download/drizzle-2009.12.1251.tar.gz

Just as before this will open up the formula in your text editor and we will need to make some edits including the projects homepage, md5 checksum, show a dependency on libdrizzle, the configure arguments and a line to make the datadir for drizzle. Again you can compare it against my copy of the formula.

All that is left is to install drizzle.

brew install drizzle -v

As long as you get no errors you should now have a copy of drizzle installed that you can start with:

drizzled --datadir=/usr/local/var/drizzle --console-enable

More information on Homebrew, Drizzle or some of the other package management tools for Mac OS.



 

Feel free to share your comments using twitter or email.

View the previous article: or find more in the archives.