Using rvm to check out Rails 3

2 minute read

I’m posting this because someone I did a Hack night with hadn’t yet checked out the awesome rvm in order to muck around with Rails 3. If you’re a Rail or Rubyista you need to install it and start messing around with 1.9.x and the wonders that are Rails 3. Here’s how.

Rails is now at beta 3 which means a release candidate is right around the corner. While fundamentally more complex under the hood than 2.x (though the devs claim it’s easier to understand now), 3 provides some fundamental advantages (and some key changes) you probably need to get up to speed with if you don’t want to be left behind.

BTW, Ryan Bates’ Railscasts episode 200 is a great step-by-step screencast on this same process if you prefer his mellifluous tones.

The easiest way to do some checking seamlessly is to install RVM (Ruby Version Manager). This creates compartmentalized ruby environments for you which means you can leave your current ruby environment (system) in place while playing around with ruby 1.9.1 and Rails 3 (you only need 1.8.7 to use Rails 3 but ruby 1.9.x is much faster than 1.8.x so use it). Install rvm and then type

rvm install 1.9.1

Grab a cuppa joe as it’ll be a while downloading and installing. You can also add some options here to get the x86_64 version and such (since this’ll go 386 on ya), I’ve seen the following?

When it’s done, go rvm 1.9.1. Check it’s switched with ruby -v. You should see ruby 1.9.1p378 (2010-01-10 revision 26273) [i386-darwin10.3.0]

Then it’s a simple matter of installing gems. Make sure you don’t use sudo gem under rvm since rvm modifies the $PATH to work its magic, use rvmsudo (You can use straight up gem install but when I tried this I got permission denied errors.).

So, then just paste the following in your terminal (you have to install dependencies manually) :

rvmsudo gem install tzinfo builder memcache-client rack rack-test erubis mail text-format bundler thor i18n
rvmsudo gem install rails --pre

You’l also need a database store of some desciption. sqlite is the default so you’ll need to install this :

rvmsudo gem sqlite3-ruby

Personally, I never use sqlite, and find MySQL is what I like for dev, and most people will be using it, so if that’s you too, you need to do the following :

env ARCHFLAGS="-arch x86_64" rvmsudo gem install mysql -- --with-mysql-config=/usr/local/mysql/bin/mysql_config

That’s it. You’re all set. To create your first Rails 3.x app, just type

rails your_app_here -d=mysql

And off you go.

dev ruby rails