How to Switch Between Multiple Ruby Versions using Command Line

I am using ubuntu 12.04 and my machine got reset to the system version of ruby while installing the gem. I was not aware of how to switch between the versions. Here's how I figured out how to do that.

sudo update-alternatives --config ruby

sudo update-alternatives --config gem

You can first use rvm list and rvm use to check if you can switch between the versions that way and if it didn't worked then you can these commands in terminal. It works just fine and gets you the preferred version of ruby.