Quick MacPorts Installation of Ruby on Rails

October 2010 update: I wrote this a while back, before I knew about RVM. The Ruby Version Manager has a bunch of features that makes it better than macports for ruby and gem installation. Read about it here.

I finally got to walking through a great gentle introductory ALA article on Ruby on Rails. I wanted to run rails Demo to build my first project, but I got nastiness:

$ rails -v
/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/rubygems.rb:379:in `report_activate_error': RubyGem version error: rake(0.7.3 not >= 0.8.3) (Gem::LoadError)
        from /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/rubygems.rb:311:in `activate'
        from /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/rubygems.rb:337:in `activate'
        from /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/rubygems.rb:336:in `each'
        from /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/rubygems.rb:336:in `activate'
        from /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/rubygems.rb:65:in `active_gem_with_options'
        from /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/rubygems.rb:50:in `gem'
        from /usr/bin/rails:18

That’s not especially welcoming. Let’s see if MacPorts can come to the rescue.

After installing MacPorts, this got me going:

sudo port selfupdate
sudo port install rb-rubygems
sudo gem install rails

I saw this from the gem install rails:

Successfully installed rake-0.8.3
Successfully installed activesupport-2.2.2
Successfully installed activerecord-2.2.2
Successfully installed actionpack-2.2.2
Successfully installed actionmailer-2.2.2
Successfully installed activeresource-2.2.2
Successfully installed rails-2.2.2
7 gems installed
Installing ri documentation for rake-0.8.3...
Installing ri documentation for activesupport-2.2.2...
Installing ri documentation for activerecord-2.2.2...
Installing ri documentation for actionpack-2.2.2...
Installing ri documentation for actionmailer-2.2.2...
Installing ri documentation for activeresource-2.2.2...
Installing RDoc documentation for rake-0.8.3...
Installing RDoc documentation for activesupport-2.2.2...
Installing RDoc documentation for activerecord-2.2.2...
Installing RDoc documentation for actionpack-2.2.2...
Installing RDoc documentation for actionmailer-2.2.2...
Installing RDoc documentation for activeresource-2.2.2...

I had some issues because my PATH included /usr/bin before /opt/local/bin (so MacOS’s old gem binary got picked up before MacPorts’ version). You can tell you’re running the correct version:

$ which gem
/opt/local/bin/gem
$ gem -v
1.3.1

If you see version 1.0.1, you’re still need to follow these instructions to install MacPorts. Add something like this to your ~/.bashrc or ~/.profile:

export PATH=/opt/local/bin:/opt/local/sbin:$PATH

Anyway, looks like things are good now. Yea new toys.

Great Frank Lloyd Quote

An architect’s most useful tools are an eraser at the drafting board and a wrecking ball at the site.

Software isn’t nearly as hard to refactor as studs, drywall, and joists, but it’s still cheaper and faster to start only after you’ve got a blueprint. A blueprint balanced with KISS and YAGNI, of course.