Software-Related Intel

04/02/2010

Homebrew or: How I Learned to Stop Worrying and Love Package Management

Homebrew is package management system for OS X designed to automatically tune build configurations for your system. No more fumbling with compile flags. No more mucking up your $PATH with various installation locations. Just use ‘brew install package_name’ and let Homebrew handle the rest.

Installation

I recommend installing Homebrew as a git repo in /usr/local. I’ll cover some benefits of this later.

$ cd /usr/local
$ git init
$ git remote add origin git://github.com/mxcl/homebrew.git
$ git pull origin master
$ sudo chown -R `whoami` /usr/local

The last command is to eliminate the need of sudo when installing a new formula.

Here are some of the key folders in the Homebrew directory:

bin/

(not tracked by git)

Initially, this contains only the brew executable (for installing and maintaining packages). When a package is installed, a symbolic link is created here which points to the executable in the package installation

Cellar/

(not tracked by git)

Packages are installed in their own folder here. (e.g.- /usr/local/Cellar/mysql/5.1.41/). Different versions are separated into sub folders. This way, you can have multiple versions of the same package built and ready for use. Just change the destination of the link in bin/ to point to a different version.

Library/Formula/

This folder contains all of the Homebrew formulae. Each formula is a Ruby class which uses a DSL to craft the package build recipe. As of this writing, there are 469 formulae that come in the default Homebrew package. If your desired formula is unavailable, check Github or add your own.

Cherry-picking Formulae

So far, so good. I have built every package that has previously given me problems (i.e.- mysql, postgres, imagemagick). I thought I would try something a little more obscure: MacVim.

Error: No available formula for macvim

Denied…Github to the rescue!

I could take the lame route by pasting this to a file in my local Formula folder, but lets show off how easy Github+git makes sharing code.

First, I setup d0k’s fork as a remote git repository in my homebrew repo

$ git remote add mac_vim git://github.com/d0k/homebrew.git

Now, I can fetch all of d0k’s changes not in my homebrew repo (remember, fetch pulls down the changes but does not merge them in).

$ git fetch mac_vim

Using cherry-pick, I can apply the single MacVim commit to my local repo. All I need is the SHA (accessible via Github or logs). In the master branch, execute:

$ git cherry-pick 1dd0594acbe80b52d26175c2ae97314967a02f06

That’s it! Git automatically knows which branch based off the SHA and commits that change to my current branch.

Now,

$ brew install macvim
Comments
blog comments powered by Disqus
Tumblr » powered Sid05 » templated