Are you using RVM correctly? | BlueDiapente - Lilibeth De La Cruz


Are you using RVM correctly?

Today I realized I wasn't using RVM correctly. Well, that is one judgemental way to say that I was using it for very little of what it's full capacity allows. Though I guess it is worse if I wasn't using it at all.

RVM is the Ruby Version Manager. The value that RVM provides is that it solves very well the problem of handling different Ruby and RubyGems version requirements for projects.

You could have a project you worked on with Ruby 1.8.7 that you are still supporting, but have a new project for which you want to use 1.9.2 or whatever the latest is. What are you supposed to do in that case? The options are not many and are not pretty:

  • You could just update your Ruby version to 1.9.2 and then have issues when working on something built against the older one (you might not be able to upgrade it due to reasons like time, hosting, other developers, etc.).
  • You could compile them from source and name them accordingly that would be cumbersome and require you to be very organized.
  • I'm sure there are others...

RVM seems to be recommended as the best solution and I think it is well deserved. It allows you to have different Ruby versions installed and switch between them with a simple command. The switch is transparent and you can just keep working (pretty much) as if the other version never existed.

It also allows you to have small named packages called gemsets (which they recommend you have one per project configuration or environment you are testing) that are made of a specific Ruby version and a series of gems with certain versions.

Another very useful features are allowing you to specify a file within a project that defines the gemset it uses and also allowing you to bundle those gems. This way you can specify a certain Ruby version with certain gemsets that the project uses and share them among developers increasing the chances of a consistent environment.

There are many more things you can do with RVM to make you a better and more productive Ruby developer. In no way do I try to be exhaustive about how to use it, just give an idea of some very basic, but useful things it can do. If you want to get started with RVM then I can recommend this blogpost I found very useful by a developer that seems to have gone through the same revelation a while ago and of course the RVM website's own documentation.