Monday, January 30, 2012

Introduction towards using Ruby enVironment Manager

As I have been using RVM for quite a while during recent times, I felt it was necessary to give a quick introduction of it.

Similar to bundler, the dependency management tool, this sort of has become the de-facto method of setting up development environment in the ruby community.

Basically , this is a bundler for the entire ruby platform, or the ruby application stack. By using this, at a given project, we can specify the version of ruby that application runs upon (yes,  even its different ports like jruby and ironruby) and its different gems.

To install, it is recommended that you install from the default location as mentioned from the website itself as the bleeding edge projects tend to migrate and change their locations quite often.

After a single step installation and setup, you can perform different steps, some of which are :

Installation of platforms

rvm install

for eg : rvm install ruby-1.9.3

This will install the given version of ruby platform by fetching its source tarball into your .rvm/archives folder at home location and build that ruby from source

Testing of all platforms managed by rvm

rvm do ruby [filename.rb]

This will run the ruby command on all installed

Selection of an installed platform

rvm use

for eg : rvm use 1.8.7

This searches for an appropriate version of ruby and specifies steps for installation of that version if it is not present in the rvm.


In line with the compartmentalization introduced at platform level, rvm also provides the same at gem level. We can create different 'schemes' containing specified gems of specific version.

The gemsets are namespaces having different combinations of gems. This solves a lot of headache from developers as newer versions can be tried without compromising on stability of existing systems.

Creating gemsets

rvm gemset create 

This creates different gemsets which are used in the following manner :

rvm @[gemsetname]

This sets our current gemset and now we can install any gems that we like using the gem install -v version gemname here.

The version@gemset name is unique and will have these configurations saved.

Using gemsets

After the creation you can load a gemset configuration through:

rvm use version@gemset

rvm use gemset

There are host of other options that we may use, but these are enough to get started (as in git, where the necessary commands are a breeze once we understand its intent). Since I am currently working on only hobby projects based on ruby, I have not used rvm's advanced topics yet. I would update here as I come across other exciting facets of this technology.

No comments: