OS X is Awesome…But
There are so many things that I love about OSX. I love the stability, I love Exposé, I love the font rendering, I love the pretty UI, and I love that there’s some *nix (NetBSD) under the hood. I can run SSH from my terminal window, I can grep, and I can Curl. So many things to love! One thing that is sorely missing though, is a package management system. Linux users are familiar with the idea of installing software via a package management utility, as the functionality is core to modern distributions. Installing a piece of software is as simple as running a one line command from the terminal window, providing that the piece of software you’re looking for is in the distribution’s repository (or you’ve told the package manager where to look by adding a third party repo).
$ yum install bind9
The command above is an example of using the Yum package manager on a RHEL based Linux distribution. It goes out to the Internets and downloads the appropriate BIND9 binary for the platform and installs it, along with any other prerequisite packages, or dependencies.
A utility like Yum (used by RHEL based distributions) or Apt (used by Debian based distributions), and a corresponding set of repositories for the OSX platform is sorely missing. What about the Mac App Store you say? Well, as lovely as that little gem is, there are many small *nix utilities that are not part of the scope, for example: wget, everyone’s favourite utility for pulling content from a web server – not available on the Mac App store.
One of the key components of BSD-based operating systems is the idea of a Ports collection. Essentially, Ports is a repository of source code and recipies called makefiles. Whereas the majority of package management systems being used by Linux operating systems just download pre-compiled binary files – essentially a prebuilt executable – the Ports system compiles the application into an executable binary from scratch. Doing this can lead to potentially faster performance, and smaller file sizes for the resulting binary. Being that OSX was built on a BSD kernel, it would make sense that there is a Ports collection; however, third party resources have to make up the slack. There are a couple of different resources that attempt to fill void in OS X, such as MacPorts and Fink, but we here we will be discussing Homebrew.
I Like Beer
Homebrew uses Recipes to download and compile software to run on your OS X machine. The source code itself can be pulled from all over the Interwebs, but the repository of Recipes is located on Github. If you’re not familiar with the Git distributed revision management system, there’s a great O’Reilly book over here: Version Control with Git, 2nd Edition. Recipes at their core, are simple Ruby scripts that contain a location of the source code, and any compile time parameters that are required to make things work on OS X.
Download All The Things
The first step in installing Homebrew, is taking care of the prerequisite installation of the Xcode command-line tools. If you already have Xcode installed, then please skip ahead; however, for those of us who don’t, and don’t want to install the full 2+ GB package, we can install simply the required command-line tools — essentially, the GCC compiler plus some other goodies. Fortunately for us, since OS X 10.9 was released, Apple has made installing the command-line tools a breeze. From your terminal window, simply enter:
$ xcode-select —install
You’ll be prompted to install the command-line tools, which should finish briefly.
Once completed, a simple ruby script is called to install Homebrew. The script itself may change from time to time, so please grab the latest from Homebrew. Homebrew creates a new folder called
/usr/local/Cellar, and then creates symbolic links to the binaries stored there.
$ ruby -e "$(curl -fsSL https://raw.github.com/Homebrew/homebrew/go/install)"
You will see something resembling the following, as Homebrew is installed:
==> This script will install: /usr/local/bin/brew /usr/local/Library/... /usr/local/share/man/man1/brew.1 Press ENTER to continue or any other key to abort ==> /usr/bin/sudo /bin/chmod g+rwx /usr/local ==> /usr/bin/sudo /usr/bin/chgrp admin /usr/local ==> Downloading and installing Homebrew... remote: Counting objects: 144683, done. remote: Compressing objects: 100% (47375/47375), done. remote: Total 144683 (delta 102497), reused 137154 (delta 96243) Receiving objects: 100% (144683/144683), 21.47 MiB | 4.63 MiB/s, done. Resolving deltas: 100% (102497/102497), done. From https://github.com/Homebrew/homebrew * [new branch] master -> origin/master HEAD is now at 4c7bc9e graphicsmagick 1.3.19 ==> Installation successful! You should run `brew doctor' *before* you install anything. Now type: brew help
And voilá! Homebrew is now installed on your system!
The next step to take is to run the
command. This command can be run at any time to see if there are any
issues with Homebrew’s installation, your path files, or other other
related configuration issues.
$ brew doctor Your system is ready to brew.
Before we install any packages, we will quickly make a change to the
the user’s path file. Sometimes symlinks are installed in the
folder, and the folder needs to be added to the $PATH so that you don’t
need to use the full pathname to launch the binary. If you have any
packages installed where this is a requirement, the
brew doctor command will notify you. We will go ahead and make the change right now though, in order to get it out of the way.
$ echo export PATH='/usr/local/sbin:$PATH' >> ~/.bash_profile
The last thing to do, is to actually install software on our box! Homebrew uses the simple format
brew install <recipe name>, which makes installing as easy as using Yum or Apt. Let’s first search for a package, using the
brew search function. To search for the recipe for Git we do the following:
$ brew search git bagit git-cal git-flow git-multipush git-tracker libgit2 easy-git git-cola git-flow-avh git-now git-url-sub magit geogit git-crypt git-flow-clone git-sh giter8 stgit git git-encrypt git-ftp git-ssh gitslave topgit git-archive-all git-extras git-gerrit git-tf legit git-tig
We are presented with all of the recipes with git in the title. To install Git it is simply a matter of invoking the install command. All required dependancies are also installed along with the desired software, so one is never stuck in dependency hell. The source is then pulled down from the repository, and compiled directly on your machine:
$ brew install git ==> Downloading https://downloads.sf.net/project/machomebrew/Bottles/git-126.96.36.199.mavericks.bottle.tar.gz ######################################################################## 100.0% ==> Pouring git-188.8.131.52.mavericks.bottle.tar.gz ==> Caveats The OS X keychain credential helper has been installed to: /usr/local/bin/git-credential-osxkeychain The 'contrib' directory has been installed to: /usr/local/share/git-core/contrib Bash completion has been installed to: /usr/local/etc/bash_completion.d zsh completion has been installed to: /usr/local/share/zsh/site-functions ==> Summary /usr/local/Cellar/git/184.108.40.206: 1334 files, 29M
And we are now ready to test our Git installation:
$ git status fatal: Not a git repository (or any of the parent directories): .git
There we have it! (The above error message is thrown by Git because there is no defined repo; a.k.a: it’s working). Git has been downloaded, compiled, and is running on our machine.
Keeping up with the Joneses
Now that we have packages installed, it only makes sense that at some
point we might want to update them. Lucky for us, Homebrew makes it a
snap. Using the
brew update command will pull down the updated list of recipes, and the
brew upgrade command will bring the software up to date:
$ brew update Updated Homebrew from 59ac85f0 to 4c7bc9ec. ==> New Formulae atdtool theharvester ==> Updated Formulae crash graphicsmagick libuv mu passenger rust ume youtube-dl ctail hbase libxmp mutt qt5 safe-rm v8
Because we just installed Homebrew, there will be no packages to upgrade, but the following command can be used to run the script:
$ brew upgrade
Finally, at some point in time, you may get tired of your awesome free software and feel the need to remove it. Well, rest easy, as like everything else with Homebrew, removing packages is easy as cake.
In order to view what software we have installed, we can issue the
brew list command:
$ brew list git pkg-config
brew uninstall to remove:
$ brew uninstall git Uninstalling /usr/local/Cellar/git/220.127.116.11…
Done Like Dinner
And there you have it! Homebrew is an excellent tool that can be used to some great free software, and fill in the some of the gaps with OS X. Fast, and simple to use open-source software. What’s not to like?