If you’re doing any Ruby on Rails or other open source development on your Mac, you’re going to need Homebrew.
What is Homebrew?
Homebrew is a package management system for your Mac. Homebrew makes it easy to install the software you generally need for Ruby on Rails development. Sometimes when you install RubyGems for your project, they will be dependent on software being installed on your Mac. One of the more obvious examples would be a MySQL gem and the actual MySQL Database Server. You install the MySQL Database Server using Homebrew! One of the less obvious examples would be the Nokogiri gem. This gem uses a software package named libxml2. You would install the libxml2 software package using Homebrew in order to install the Nokogiri RubyGem.
So how do you install Homebrew?
Installing Homebrew is dead simple. However, it does have a rather large dependency. You will need the command line tools addon of Xcode installed. Xcode is made by Apple and its used to write Mac and iOS applications. Xcode is free and all you need to do is search for it on the Mac App Store and click install. Its a rather large application, so it may take a while to download and install.
Once you’ve finished installing Xcode. You will need to open Xcode and choose Xcode -> Preferences. Choose the Downloads tab and install the Command Line Tools.
This will take some time, but when its done your Mac will be ready to install Homebrew!
If you visit the Homebrew website, you will see the following command:
ruby -e "$(curl -fsSL https://raw.github.com/Homebrew/homebrew/go/install)"
This command will need to be run in the OS X Terminal App. This means copy and pasting it into the Terminal window and pressing ENTER.
When the command is complete you should be able to run the following command in the Terminal window:
If this works, then Homebrew is installed!
Now let’s go over a few common tasks you will have with Homebrew.
You want to use this command after system changes (such as OS X or Xcode updates) or if you think you need to troubleshoot your Homebrew installation. The output will tell you what’s wrong and generally how to fix it.
This will update your Homebrew formula list. Note, this doesn’t update all your installed packages! What this does is update the versions and availability of packages you could install. You want to run this often to keep your Homebrew installation up to date with the latest available software.
This will upgrade your installed packages.
brew install [insert package name here]
This will install a software package onto your system.
This will list all the packages that are currently installed on your system.
brew info [insert package name here]
Sometimes after you install a package, you get a screenful of information or configuration steps. If you’re like me, you will probably blow right past that and keep working – then it will dawn on you that you probably should have read some of that stuff. This will let you go back and do that.
brew uninstall [insert package name here]
And finally, you may want to remove a package you previously installed. That’s what this is for.
So that’s a quick intro to Homebrew and how you can manage software dependencies for RubyGems on your Mac!