I’ve been using rvm for many years, and love it. Â Yes, I know that it rewrites simple commands, such as “ruby” and “gem”, so that I can use lots of different Ruby versions. Â Yes, I know that it can be overkill for certain situations. Â And yes, I know that rbenv is preferred by many.
But I’ve been using rvm for a long time, and I find it works very well for my needs. Â I can (and do) have many different versions of Ruby running on my computer, and having access to all of them at once is terrific.
I tend to be obsessive about updating Ruby gems on my systems, and I’m sure I’m not the only Rubyist who runs “gem update -V” (and yes, I love the “verbose” option) at least once per day. Â Updating gems never removes the old versions, and if you’re using Bundler in your Rails or Sinatra application, then it doesn’t really matter how many versions you have on your system. Â (And yes, I know that willy-nilly updating all gems on my system is probably not wise. Â If only that were the most foolish thing I do…)
The thing is, when I update gems, I do so in a particular version of Ruby. Â So even though I’m always running “gem update -V”, I never quite remember which versions of Ruby have the latest gems, and which haven’t been updated in a while. Â There is, of course, a clear correlation between the frequency with which I use a Ruby version and the freshness of the gems for that version on my system. Â But I sometimes find myself having to update gems in a version of Ruby that I haven’t used in a while.
So you can imagine my delight when I discovered “rvm do”. Â This is an rvm command that lets you execute a command in any or all of the Ruby versions installed on your system. Â It basically switches to the Ruby version and then executes the requested shell command — so you’re not executing a Ruby program in each separate version, but rather you’re executing a command-line program once for each version of Ruby installed. Â You can think of it as executing the same shell command once for each installed version, prefaced by “rvm VERSION_NUMBER”.
So, how can I ensure that all of the gems, for all versions of Ruby, are up to date? Â Very simply, I write:
rvm all do gem update -V
And if I want to check out some Ruby code, and see how it runs in all of the versions on my system, I can say
rvm all do ruby test.rb
If I just want to see the difference between doing something in 1.8, 1.9, 2.0, and 2.1 (without all of the patchlevels for 1.9.3), then I can just say:
rvm 1.8.7,1.9.3,2.0,2.1 Â do ruby test.rb
I’m already loving this feature, and can easily imagine cases — such as when teaching Ruby programming, and trying to show them the differences between versions — when this will be quite handy.