← back to the blog
fousa blog
Using multiple Ruby versions
I was working on a project that still on Ruby 1.8.5 and locally I was using 1.8.7. At first you'd think, no problem! But reality showed me I was wrong...
The count method wasn't supported on Arrays in the older version but I used it in my code and it worked with the newer version... So this failed in production!
That's why I looked for a way to easily switch between user versions on my development machine. The best way was to use the Ruby Version Manager.
Install
Run the following command to install RVM.
sudo gem install rvmrvm-install
When the installation is complete, please follow the guidelines in your terminal to complete. In my case I had to add the following line to my ~/.bash_profile.
if [[ -s /Users/Usage
Now let's use RVM. It's very easy.
Switch to a certain version of Ruby like this:
rvm use 1.8.6rvm use 1.9.1
When that version on Ruby is not installed RVM will notify you. And you'll have to run the following command to install the version:
rvm install ruby-x.x.xWhen you want to return to use your default version on Ruby just do this:
rvm use defaultWhen you want to return to use your original system version on Ruby just do this:
rvm use systemFor me it worked fine! Without any problems with my gems. The only downside is that you have to reinstall all your gems.
Send me some feedback!