Blog

Homebrew: OS X’s Missing Package Manager

By | 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.

  • Anon.

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

    Wow, are you joking?

  • Anonymous Coward

    Agreed. If you want to own the directory where packages are installed, you ought to install it under your user's directory.

  • http://tomafro.net Tom Ward

    +1. I've been using homebrew installed under ~/.homebrew for 3 months or so, with no issues at all. I'm very happy with it.

  • http://mikearthur.co.uk Mike Arthur

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

  • bryanl

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

  • mxcl

    Yeah, I have a patch for that to apply.

  • mxcl

    There is issues with not installing to /usr/local. Mainly some build scripts break because they can't find their deps. You can often fix that if you know what you're doing.

    This mainly happens for RubyGems (and that) that depend on some c-library.

  • mxcl
  • arathoward

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

  • Indirect

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

  • Gene

    "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.

  • http://iamnotaprogrammer.com Colin Nederkoorn

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

  • http://iamnotaprogrammer.com Colin Nederkoorn

    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.

  • Elk

    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?

  • http://intensedebate.com/people/kevinelliott kevinelliott

    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).

  • http://alex.tsd.net.au/cpill CpILL

    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.

  • .jon

    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

    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.

  • Duff

    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?

  • http://blog.xdite.net/?p=1795 Blog.XDite.net » 在 Mac 上建立乾淨的 Rails 開發環境 ( OSX 10.6 Snow Leopard )

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

  • http://ihelpxu.blogspot.com Marty Phlipmann

    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!

  • Dave

    Good grief.. Has everyone forgotten 'groups'?

  • maloke

    The directory /usr/local/mysql is usually a link to the real mysql directory. So you have to run chown on that one as well

  • Grigory Entin

    I'll stick to toast (http://www.toastball.net/toast/). That's a Perl script (one file) that does most of the things homebrew does, except the dependency tracking (I feel comfortable with that). It doesn't require knowledge of Ruby nor Perl, doesn't require editing the config files to override something (but saves your overrides from the command line), (by default) doesn't install to /usr/local but to ~/.toast/armed (keeps packages in ~/.toast/pkg), provides some hacks to fool config/make/install scripts so that in 90% of cases you don't need to supply even "prefix" and etc. and etc. Take a look at it, if you want *simple*/self-contained but powerful package manager, without dependency on Ruby and with simpler config files (compared to homebrew) (actually you don't deal with them at all).

    For the illustration, below is dump of my toast configuration for flac (there're two urls, and two command line options, everything else is just a generated text) and for wget (you get it). (Note that I prefer not to use mirrored/local tarballs, hence you see local urls; toast by default perfectly searches/fetches from freshmeat and etc.):

    >>>
    % toast status flac
    flac
    version 1.2.1-macports
    urls:
    file://localhost/Users/eg/mirrors/downloads.xiph.org/releases/flac/flac-1.2.1.tar.gz
    file://localhost/Users/eg/packages/toast/share/toast/flac/1.2.1/flac-1.2.1-macports.diff
    options:
    –confappend='–disable-static –disable-asm-optimizations'
    –makeappend='OBJ_FORMAT=macho'
    build 3: armed
    >>>

    >>>
    % toast status wget
    wget
    version 1.12
    urls:
    file://localhost/Users/eg/mirrors/ftp.gnu.org/gnu/wget/wget-1.12.tar.gz
    build 3: armed
    >>>

  • Zorg

    I think this is going the wrong way, same as MacPorts and Fink.

    Rudix (http://rudix.org/) is the way to go. Simple binary packages built in a common-sensical way, nothing to compile.

  • http://pulsd.com Kimball

    Beware chown'ing /usr/local and /usr/local/mysql, totally borked my whole dev environment and still trying to recover.

  • zorg

    It is distressing to see someone with my usual username malforming http://rudix.org into http//rudix.org!

  • Adam

    This ruined my dev environment, argggh!!!

  • Jaime

    Huh? You're misinterpreting the comment I think. Doesn't pull masses of junk every time… as Macports does.

  • Ryan

    It also wrecked my dev environment. Caveat emptor. Make backups first.

  • Stan

    Dev environment gone… :/

  • MySchizoBuddy

    those are dependencies. So your saying if you use homebrew those dependencies vanish in thin air and the package just works. what nonsense.
    care to give an example where macports is downloading lots of dependencies and homebrew magically works without them.

    Macports allows you to install the complete package with all it's optional dependencies.

  • MySchizoBuddy

    for small number of packages binaries work well. but try creating binaries of 7500+ packages in macports and storing all of them on the server, then you see the problem with binaries. the amount of bandwidth and storage cost will be detrimental to macports. When Fink started it used to provide binaries and gave you option of compiling it yourself or installing binaries. Soon maintainers stopped creating binaries due to lack of time and interest. result being only binaries of older versions were available.

    it's easy to criticize since you are not contributing to the effort. why don't you go ahead and compile 7500+ binaries for macports and host it for them.

  • MySchizoBuddy

    There is the duplicates issue with homebrew that isn't there with fink or macports.
    If you need a new version of a package that already comes with the os, then you are out of luck. Homebrew doesn't allow duplicates and hence your new package will be shifted to duplicates repo.

    For eg. Toped which is an open source layout editor requires a newer version of bison 2.4.1 and above. But the OS comes with 2.3. Now homebrew won't allow the newer bison and has shifted it to the duplicates branch. Long story short I don't know how to create a formula for toped that fetches the newer bison from the duplicates branch instead of using the one provided by the OS.

  • MySchizoBuddy

    ok there is an exception for dependencies of desirable products. then duplicates are allowed in the main repo. just found out

  • http://khiltd.com Nathan Duran

    I wish he were. This same prepubescent moron seems to be the only one working on Bundler anymore these days and he has no clue what he's doing.

  • dhnaranjo

    That's not how you make friends.

  • Stunned Onlooker

    It's actually worse. On that page, they say:

    We recommend you delete /usr/local/include and /usr/local/lib

    First I'm supposed to chown it. Then just delete what's there. What planet are these guys from? Even microsoft has started to outgrow the "it's my pc and I'm the only one using it" syndrome. Now it's showing up on OS-X??!! Anyone that develops software, especially install/admin software of all things, that has *this* philosophy is either totally ignorant of key issues regarding unix administration or they are an idiot. I really don't care which it is — ain't no software from these guys getting within 100 yards of my systems. Sheesh. Next they'll be recommending 'chmod -R 777 /' to make it easier to do updates.

  • Mohawke

    Just install Linux using bootcamp or run it in Virtualbox and be done with it. if you want to run software or dev for Unix/Linux why pay more for the hardware anyway? Just buy a cheap ass Dell and install Linux. If you don't like the look of non-Apple hardware, hide it in another room – perfect use of a router. Oh, and SSH is your friend:

    Select xterm from x11 and type:

    sudo ssh -Y linuxuser@lunuxmachine someapp

  • Eric

    homebrew uses existing dependencies installed on your system already

    For instance macports will build a separate X install, even though you already have X installed on your mac

  • http://www.jobsearch.net Peter Lee

    I stopped reading once I saw this on their Wiki page:

    We recommend you delete /usr/local/include and /usr/local/lib

  • jomo

    Here is no good package management for OS X (yet). ;(

    I'm started with Fink, and stopped used it a few years ago, now don't remember why. I'm living with macports now and YES, sometimes driving me to brew a drink. :(

    Now reading about a homebrew and reading some incredible (sry brew author) thing about changing owners of /usr/local and/or deleting whole trees. Good bye brew.

    But, unfortunately – macports are bad too. I understand than here is a gigantic volunteer work in it, but the base "logic" is simply bad.

    Wan't use some perl modules? ofc – some are in ports, but if want use cpan together with macports, soon or later you will get messages like "use -f for….". for the normal user way confusing.. ;(

    What me drive to craziness are the "port variants".
    I NEVER want use any X-server based application. OK, tried adding no_X11 to default config file, No success. Some port simply don't compile. What next? Delete all /opt and start again with defaults and waiting few hours to recompile everything again. Bad bad bad…

    Another: the port's default perl is 5.8.x. Want use perl10+? OK, here are port for it too. But again, some other dependent ports simple don't compile because they want perl8. (and using nothing perl8 specific). Again, delete the whole /opt (because it is much faster, than trying deinstalling ports what are depends on perl8 – and yes, i know the port rdeps command).

    What the normal OS X user need?
    CONSISTENT, packages with GUI manager, what will "guard" your "variant dependencies" too, and having some default preferences like no_x11, universal and so on… The normal OS X user don't want X11 (or OK – want it for Gimp or so), but want for example command line ImageMagick with X bitmap support, but without installing an unneeded whole X11 lib-distro.

    and maybe – the best way:
    having only FEW base variants and installing them like fink – binaries – in consistent way.

    I will stay with macports, because (by me) macports are the best. But you should to know, you will be drunk too much times when will trying install something and after a hours you got a message like; "need install package with variant +xxx" – and you should start all over again.. (or nearly all)

    Really thank you, guys from macport – you done gigantic work and now i can't live without you. port upgrade outdated and some other things are simply brilliant, but, I'm sporadically looking for a better replacement for a macports, and therefore I'm here today.

    Unfortunately, the homebrew is not the solution to replacing macports… :(

    sry my "broken" english compilation – has no variants :D and haven't native version :D

  • http://twitter.com/AmandaStott Amanda Stott

    You are awesome! This is so much better than macports, which drives me insane.

  • http://chipotle.tumblr.com/ Watts

    MacPorts will use the system installed X11, and always has by default — I remember that back when it was called Darwin Ports. If a port attempts to install the full version of X, that’s because that port is broken. (And if you don’t want the X version, you can usually specify a no-x variant anyway.)

    I may well try Homebrew on my next Mac, because it does sound interesting, but it’s worth remembering MacPorts’ good points. I haven’t seen any other package system which is as good at not just dependency management but “variant” management. As far as I know neither Homebrew nor Fink even have the concept of variants. And as annoying as MacPorts’ habit of installing its own version of certain tools is — you really *are* stuck with having it install its own versions of Python, Ruby and Perl, for instance — the flip side of that is that MacPorts is pretty unlikely to be affected by OS X system upgrades, and that its own update schedule isn’t tied to Apple’s.

    And I admit, “we recommend you delete /usr/local/lib and /usr/local/include” is a head-scratcher. Anyone who’s ever installed any Unix software from source into /usr/local — which is where 99% of what they’d install from source would go by default — is likely to break their system in highly entertaining ways.

  • http://profiles.google.com/marsofearth Mars Sjoden

    Why?

  • Anonymous

    To anyone who is getting their panties bunched because someone dares suggest that you chown /usr/local, OS X does not install anything in there by default and very few programs not aimed at developers are going to put anything there. If your spouse or whoever wants to use your computer, I don’t see why that would matter. Unless they are also trying to brew, in which case they probably have their OWN COMPUTER. How many developers do you know that share machines?

    You can install homebrew right over the top of anything in /usr/local. You won’t be brewing packages you manually installed anyway right? So WHO CARES.

    If there was a better solution, I’d use it, but there isn’t. I know this post was from a year ago, so those of you who would suggest using gawdawful Macports or Rudix (check the available packages on Rudix v. Homebrew. Rudix is going nowhere.) probably wouldn’t still be doing that…

    The only thing I can say is if having a hacked together package manager makes you fidget, you shouldn’t be on OS X. Apple has failed to provide any package solution so people are forced to come up with their own. So far, this is easily the best solution available. If you really need a native package manager, then go buy an old black box like one commenter suggested and throw Linux on it. Or VirtualBox, whatever. Just don’t suggest that somewhere this magical solution exists where everyone is happy, because it doesn’t. Not until Apple decides to create a native package management solution, and I’d put the odds on that somewhere around 0.000000000001%.

  • Anonymous

    Actually, I shouldn’t speak ill of Macports. It did the job for a long time, but it’s really outdated in a lot of ways. Most of all, they use an arcane collaboration system, whereas if I want to submit new formulae to Homebrew, I just throw up a pull request on Github. The idea that every Macports package has a particular maintainer doesn’t sit well with me, honestly. I’d like anyone to be able to fix stuff at will instead of waiting for a blessed update.

  • http://drivenet.wordpress.com/ Mr.Drive

     Ok, so I secrewed up by taking ownership of /usr/local and by chowning -R mysql:mysql /usr/local/mysql*. Now I am freaking out after reading all these threads.. How do I restore it back to the original settings? Thanks,

  • Guest

     just tried all of the above suggested installs and none work with 10.5.x.  just get me some *** source for the command line utility I want and I can Xcode it if the “portable” calls are twisted to fit OSX.

  • http://www.mistriotis.gr/2011/07/16/installing-grails-in-osx-with-brew/ Installing grails in OS/X with brew | mistriotis.gr

    [...] good post about what is brew can be found here: Homebrew: OS X’s Missing Package Manager, and installations instructions are available in it the project's page in git: [...]

  • http://redconservatory.com/blog/switched-to-homebrew/ Switched to Homebrew // red conservatory

    [...] I am pretty pleased. I think I’m going to keep using it. There’s a terrific write up by Andre Arko that explains all the nice things about Homebrew. Tags Categories Uncategorized blog [...]

  • http://www.convalesco.org Panagiotis Atmatzidis

    I see no reason why you can’t use them both, Macports and Homerbew. In my eyes, these projects are complementary. You can’t get the flexibility of MacPorts in homebrew, but since Homebrew it’s build in a different way that makes sense.

    If you know how to actually use shell (UNIX) paths, I don’t think there’s a problem using the defaults or even $HOME/something for HomeBrew and/or macports.

  • http://www.webdesignarticles.net/help-your-business-use-a-ruby-on-rails-based-erp/ Help Your Business Use A Ruby On Rails Based ERP | WebDesignArticles.net | WebDesignArticles.net

    [...] #split {}#single {}#splitalign {margin-left: auto; margin-right: auto;}#singlealign {margin-left: auto; margin-right: auto;}#splittitlebox {text-align: center;}#singletitlebox {text-align: center;}.linkboxtext {line-height: 1.4em;}.linkboxcontainer {padding: 7px 7px 7px 7px;background-color:#eeeeee;border-color:#000000;border-width:0px; border-style:solid;}.linkboxdisplay {padding: 7px 7px 7px 7px;}.linkboxdisplay td {text-align: center;}.linkboxdisplay a:link {text-decoration: none;}.linkboxdisplay a:hover {text-decoration: underline;} function opensingledropdown() { document.getElementById('singletablelinks').style.display = ''; document.getElementById('singlemouse').style.display = 'none'; } function closesingledropdown() { document.getElementById('singletablelinks').style.display = 'none'; document.getElementById('singlemouse').style.display = ''; } 23 Amazing And Open Source Ruby On Rails ApplicationsRuby on Rails – Part 6: Configuration and Deploy _ Sound ScienceBroadband Routes – Ruby on Rails Project by WaileHelp with Mortgage Payments While UnemployedSAP Interview Questions and Answers8 Best And Free Open-Source Software For Small BusinessesWeb Programmer/ Developer – oDeskTutorial: Streaming applications: Geospatial Visualization – Part 1Homebrew: OS X’s Missing Package Manager [...]

  • Deb

    There is only one good package manager in the world today.  It’s been around for years.  For those who know I don’t even have to say which package manager I’m talking about.  For the rest of you.  Here’s a hint it starts with a d.  Once you figure it out you can quit wasting your time and work on a port and package repository for OSX.

  • Pawel Dobierski

    “Next they’ll be recommending ‘chmod -R 777 /’ to make it easier to do updates.”

    masterpiece :)

  • http://ollehost.dk/blog/2010/09/01/im-porticus-im-porticus/ I’m Porticus! I’m Porticus! | Olle Jonsson's blog

    [...] have yet to start using the popular package management system Homebrew (brew install postgres), so I was happy to find the simple, graphical Porticus package browser, [...]