Setting up Ruby on Rails using RVM

For my very first installation I’ve ever made of Ruby and Ruby on Rails I’ve used MacPorts. But doing it this way was not so satisfying. Than I stumbled upon RVM and finally found what I was looking for. From the RVM homepage:

“RVM is a command line tool which allows us to easily install, manage and work with multiple ruby environments from interpreters to sets of gems.
[...]
RVM allows users to deploy each project with its own completely self-contained and dedicated environment–from the specific version of ruby all the way down to the precise set of required gems to run the application.
[...]
RVM reduces the complexity that is the many facets of ruby development through its command line API. RVM allows you to have **identical** self-contained environments in your Development, CI, Q/A, Staging, and Production environments.”

Great! :)

So here’s how I set up my RoR playground on my Mac OS X 10.6.8.

Open Terminal or iTerm and digit as follows

kevin$ bash < <(curl -s https://rvm.beginrescueend.com/install/rvm)

than close your terminal and open your

~/.bash_profile

file. If it does not exist, create it and add at the end the following line

[[ -s "$HOME/.rvm/scripts/rvm" ]] && . "$HOME/.rvm/scripts/rvm"

Now open your console and check whether the installation was successfully performed

kevin$ type rvm | head -n1

It’s good practice to update to the head version of RVM. I tried using the update command but it seems it does not exist anymore.

kevin$ rvm update --head
ERROR: rvm update has been removed. See 'rvm get' and rvm 'rubygems' CLI API instead

so I used the get command instead

kevin$ rvm get head

and it worked.

Rails 3 requires at least Ruby 1.8.7 but seems to work best with the 1.9.2 one. Let’s install both versions so we can switch from one to the other and back.

kevin$ rvm install 1.8.7
kevin$ rvm install 1.9.2

Both will require some secs.

Now let’s use a version of Ruby and set it as the default, passing it the –default option

kevin$ rvm use 1.9.2 --default
Using /Users/kevin/.rvm/gems/ruby-1.9.2-p180

Next create a gemset, which will make available different gems for different versions

kevin$ rvm gemset create rails3
'rails3' gemset created (/Users/kevin/.rvm/gems/ruby-1.9.2-p180@rails3).

Now let’s get ready to install some Ruby gems using RubyGems. Since Rails is distributed as a gem, we will use RubyGems to install it. Download RubyGems, unpack it and then from the rubygems directory run

kevin$ ruby setup.rb

This will install RubyGems. Before going on, update it using

kevin$ gem update –system

kevin$ gem install rails -v=3.0.1

or

kevin$ gem install rails --version 3.0.1

To check gem installation execute

kevin$ which gem
/Users/kevin/.rvm/rubies/ruby-1.9.2-p180/bin/gem

Set a default rvm and default gemset

kevin$ rvm use 1.9.2@rails3 --default
Using /Users/kevin/.rvm/gems/ruby-1.9.2-p180 with gemset rails3

Let’s check the consistency of the installed versions of Ruby and Rails:

kevin$ ruby --version
ruby 1.9.2p180 (2011-02-18 revision 30909) [x86_64-darwin10.8.0]
kevin$ rails --version
Rails 3.0.1

Now we are ready to start playing with our RoR environment.


No Comments yet. Welcome to post your comment.


Leave a Reply

Powered by WordPress and theme PlainMagic.
Copyright © 2010 The Granma's garage