Install Homebrew & Ruby on Mac OSX Lion

The purpose of this article is to help you configure Mac OSX so that it has a package manager (similar to apt-get, YUM, Pacman or Portage on Linux distributions), and to update you to the latest version of Ruby (1.9.3 at the time of this writing). Currently, Mac OSX Lion 10.7.4 has Ruby version 1.8.7 which is slightly out of date.

Installing Homebrew

Homebrew is a very easy to use package management system. To view more information on Homebrew, please visit the Homebrew home page.

Enter the following command to install Homebrew – I took this directly from the Homebrew installation page:

/usr/bin/ruby -e "$(/usr/bin/curl -fsSL"

It will take anywhere from 5 to 10 minutes for Homebrew to install.

After Homebrew is installed, you can install all kinds of packages from the command line. For example, if you would like to install Nmap:

brew install nmap

To update your brew installed packages:

brew update --system

For other brew commands, type this command:

brew help

Installing Ruby

Once Homebrew is installed, you can install Ruby using the brew command:

brew install ruby

Ruby will take another 5 to 10 minutes to install.

In order to use the version of Ruby which was installed by Homebrew (instead of using the default version 1.8.6), you can modify your /etc/paths file by moving /usr/local/bin to the top of the list (above /usr/bin).

Reboot your machine and the changes will be applied.

After you log back in, you can check what version of Ruby you are using by running the following command:

ruby -v

Installing Ruby Gems

Now that Ruby is installed, you can install whatever Ruby Gems that you need. For example, if you wish to install the mechanize gem, run this command:

sudo gem install mechanize

Comments are closed.

Post Navigation