Sunday, October 28, 2007

Ruby on Rails and Leopard: A n00b's view

So Carl and I attended the Leopard release event at the Oxmoor Apple Store. I came home (t-shirt in hand), dropped the disc in my shiny aluminum iMac and performed a standard upgrade. I'm happy to report that there weren't really any problems with the upgrade itself. Here are a few things I found:

  • Quicksilver needs to be updated (as of now, their site is still down) to hide the dock icon
  • You cannot display a different space on each of your displays in a multi-display setup
  • Time machine does not completely eat a drive. It's backup can coexist with other data.
  • Disk utility permissions operations seem to run "slower"
I thought everything was fine and dandy with my upgrade! This was the first time I had chosen the upgrade path when installing a new OS X since, as a survivor of Windows, I had learned to be distrustful of such things. It wasn't until I noticed that John was online that I realized I had a problem.

I've been bound and determined to learn Ruby on Rails. While on Tiger, I followed Robby Russell's excellent Ruby on Rails on Mac tutorial and rolled my own development stack (using MySQL instead of PosgreSQL). John told me that he hadn't upgraded yet because many of his friends had run in to problems with their own Mac Ports installation of Ruby on Rails after upgrading. This is due to the fact that Leopard includes a really solid Ruby on Rails stack. For those who have a MacPorts installation of RoR and want to keep using it after upgrading to Leopard, Robby has posted instructions.

Since I am a RoR newbie and a bit OCD about where things live on a system, I decided to abandon my MacPorts installation and switch to using the native Leopard Ruby on Rails stack. Rather than being good and learning how to manually remove my installation, I decided to reinstall Leopard from scratch. Yes, this is probably akin to using a sledgehammer to hit a framing nail, but it makes the most sense in my mind :)

So now I have a fresh and happy installation of Leopard. It's time to see what shape Apple's RoR stack is in by firing up Terminal.app.

Doing ruby --version returns ruby 1.8.6 (2007-06-07 patchlevel 36) [universal-darwin9.0] Yay! Ruby is up to date.

What about Rails? Doing rails -v returns Rails 1.2.3 Hmm, Rails is slightly outdated so I should probably update it. Thankfully, this will be an easy task since gem is also installed. I'm thinking if Rails is outdated, other gem packages are likely outdated as well. Let's updated everything (since I know nothing will break since I'm still learning).

I run sudo gem update --include-dependencies. So far, so good. Several packages are updated before it asks me this:

Attempting remote update of fastthread
Select which gem to install for your platform (universal-darwin9.0)
1. fastthread 1.0.1 (ruby)
2. fastthread 1.0 (ruby)
3. fastthread 1.0 (mswin32)
4. fastthread 0.6.4.1 (ruby)
5. fastthread 0.6.4.1 (mswin32)
6. Skip this gem
7. Cancel installation


I select 1, expecting things to continue on their merry way.

Building native extensions. This could take a while...
ERROR: While executing gem ... (Gem::Installer::ExtensionBuildError)
ERROR: Failed to build gem native extension.

ruby extconf.rb update
can't find header files for ruby.


WTF???? Oh right. I've run in to a similar situation while trying to install the stack on Debian's Etch. The problem was that I didn't have make tools installed (John confirmed this for me). So how does one get those on their Mac? Easy! Drop the Leopard install CD back in your computer and select "Optional Installs", then "XCode Tools". You'll want to run XcodeTools.mpkg. Selecting the standard installation options will cover what you need to successfully get your gems updated. You won't even have to restart!

Now running gem update --include-dependencies results in Gems: [blah blah blah blah blah] updated.

Let's see if our Ruby on Rails installation works by running a demo server. I navigate to one of my project folders and run script/server start. The console reports:

=> Booting Mongrel (use 'script/server webrick' to force WEBrick)
=> Rails application starting on http://0.0.0.0:3000
=> Call with -d to detach
=> Ctrl-C to shutdown server
** Starting Mongrel listening at :3000
** Starting Rails with development environment...
** Rails loaded.
** Loading any Rails specific GemPlugins
** Signals ready. TERM => stop. USR2 => restart. INT => stop (no restart).
** Rails signals registered. HUP => reload (without restart). It might not work well.
** Mongrel available at 0.0.0.0:3000
** Use CTRL-C to stop.


Hooray! Navigating Firefox to http://localhost:3000/ results in the "Welcome Aboard" rails demo page! Hooray! I now have a working and up to date Ruby on Rails installation! Next time, I'll go through installing MySQL so real web development work can begin.

10 comments:

Jordan said...

I like puppies!

Brad Carson said...

Thanks, Jeremy. The XCode install fixed the fastthread build error for me also, but I did get a couple weird messages: "No definition for dummy_dump" and "No definition for rb_queue_marshal_load".

Everything appears to be working though.

Anonymous said...

No need to install all of XCode to get the ruby header files. Just custom install the Unix Development Support and uncheck all others.

- Jamie Hoover

Anonymous said...

This helped. Any Luck w/ MySQL?

eljacob said...

Thank you, the XCode hint worked for me.
I installed MySQL 5.0.45 and the GUI Tools using the default dmg installers (http://dev.mysql.com/downloads/mysql/5.0.html#downloads) and they are working fine.

Andrew Grimm said...

I also got those phrases with fastthread, and I'm running on Fedora Linux.

David said...

A real n00b here: I accidentally installed fastthread 1.0.1 (mswin32) instead of fastthread 1.0.1 (ruby). Anyone know how I can install the correct one now?

bparanj said...

Uninstall it by sudo gem uninstall gem_name. Then run sudo gem install and pick the right version.

Vaughan said...

Nice one Jeremy. Looking forward to a n00b's view on mysql+ror+leopard. Hope you take some time to enjoy your new Patriot :)

nuge said...

Hi Jeremy!

Thanks a boatload for your article.
My problem was with my MacBook laptop and I forgot to do the Xcode installation. (see my post on Railsforum ... http://railsforum.com/viewtopic.php?pid=79103#79103)

At any rate, I came across this post and resolved the issue.

Many thanks!
Tom