Preparing Mac OSX Lion for Rails Development

With Mac OSX Lion being released recently, I decided to do a clean re-install my development iMac from scratch, rather than doing an upgrade. This offered me the opportunity to fine tune and document my development environment setup. Without further ado, here’s how I set up my environment. I hope it helps any new Lion or Rails developers out as well.

Here’s an overview of my process:

  1. Install OSX Lion
  2. Install Apple developer tools
  3. Install RVM
  4. Install Ruby 1.9.2
  5. Install Homebrew
  6. Install MySQL

Note: this is not an introduction to Ruby, Rails, RVM, terminal, or other developer tools. I assume you already understand these, so I won’t be spelling out, for example, how to edit your .bash_profile from the terminal.

Install OSX Lion

The App Store wants you to download and install Lion on top of Snow Leopard.  In order to do a “clean install”, you’ll need to create a Lion installation DVD or USB drive. I used an 8GB USB stick for mine, but you can use any external media with at least 5 GB of space.  It’s pretty simple, and a very detailed tutorial is available at Information Week for creating the installer.

Reboot your Mac with the DVD or USB stick plugged in, and hold down the option key while booting to select the new installation media. Once the installer is running, choose Disk Utility from the Utilities menu and erase your main hard drive partition.

Note: a clean install means reformatting and completely erasing your hard drive, so be sure you 1) have a complete backup of all your applications and data, and 2) are ready to spend the time re-installing said applications and data when you’re done.

A clean install from scratch is not necessary, but I like using it to clean up years of accumulated junk and to know my operating system is in a reliable state.

Install Developer Tools

Now that you’re running a nice, clean, new version of Lion, you should immediately run “Software Update” from the Apple menu, to ensure you’re on the latest version.

Next, you’ll need to install Xcode, Apple’s software development environment—it’s a free download from the App Store. Once the download finishes, you will need to run the “Install Xcode” application found in your Applications folder.

The Xcode installer is a 3.2 GB application, so if if you have a small hard disk (for example, a solid state disk), you can safely move or remove the installer from your Applications folder to save space once the installation is complete.

If you’re not planning to do native iPhone app development, you can also delete the two iPhone folders in /Developer/Platforms/ to recover another 4.6 GB. You’ll still be able to create web applications for the iPhone, just not native apps. Or, to be extra clever, you can prevent installation of these files altogether: instead of running the “Install Xcode” application, right-click on it and select “Show Package Contents”. Navigate to Contents/Resources and run the Xcode.mpkg installer instead. This installer lets you select which components to install, and you can deselect the “iOS Platform” tools before they get installed.

Installing Ruby and RVM

Even though OSX comes with Ruby, you will almost certainly want to install a newer version and maybe multiple different versions, and that means using RVM. Go ahead and install it following the RVM installation instructions:

[cc lang=’bash’ line_numbers=’false’]
bash Install Homebrew and MySQL

I need to use a variety of third-party and open source development tools, and there are several ways to install these. I use Homebrew, which describes itself as “the easiest and most flexible way to install the UNIX tools Apple didn’t include with OS X”. Run the installer:

[cc lang=’bash’ line_numbers=’false’]
ruby -e “$(curl -fsSL https://raw.github.com/gist/323731)”
[/cc]

Now you can easily install Mysql and any other tools you may need to do some Rails development:

[cc lang=’bash’ line_numbers=’false’]
brew install mysql
[/cc]

After the MySQL installation completes, you have a few more steps to follow, that will be outlined in the brew output. These configure MySQL and set it to start automatically:

[cc lang=’bash’ line_numbers=’false’]
mysql_install_db –verbose –user=`whoami` –basedir=”$(brew –prefix mysql)” –datadir=/usr/local/var/mysql –tmpdir=/tmp
mkdir -p ~/Library/LaunchAgents
cp /usr/local/Cellar/mysql/5.5.14/com.mysql.mysqld.plist ~/Library/LaunchAgents/
launchctl load -w ~/Library/LaunchAgents/com.mysql.mysqld.plist
[/cc]

Brew installs programs into /usr/local/bin, which is after /usr/bin in the standard OSX command search path. This means if you were to brew install git to get a newer version of git, you would still end up running the standard OSX git unless you edit $PATH in your .bash_profile to move /usr/local/bin to the beginning of the list.

Trying It Out

Now, let’s see if things are working:

[cc lang=’bash’ line_numbers=’false’]
gem install rails –no-ri –no-rdoc
rails new foo -d mysql
bundle exec rake db:create
[/cc]

Looks like things are working! Now, on to choosing the all-important desktop background picture…

3 Comments to “Preparing Mac OSX Lion for Rails Development”