RVM is a critical part of your Ruby on Rails development stack. Why? Because it allows you to work in multiple Ruby environments. As soon as you build out more than one project you could find yourself having to deal with one project at a certain version of Ruby and another project at a different version. Without a tool like RVM. This can be a huge headache. Fortunately, installing RVM is pretty easy.
So let’s start on a bare OS X system. You’ll notice you have Ruby installed already by running the following command in the OS X Terminal App (all the commands in this post should be run in Terminal):
ruby 2.0.0p481 (2014-05-08 revision 45883) [universal.x86_64-darwin14]
At the time of this post, the Ruby on my OS X 10.10 Yosemite was 2.0.0 patch level 481.
What you should be comfortable determining is whether or not you are seeing the OS X version of Ruby or the RVM version (the one you want).
So lets see the path to the ruby executable:
The output /usr/bin/ruby tells you that you are referencing the built in OS X ruby. Let’s fix that.
Here’s how you install RVM:
\curl -L https://get.rvm.io | bash -s stable --ruby
This could take some time to finish. When it does, run the previous command again to check your ruby executable path. It should read:
See that .rvm in the path? That means RVM is installed and being properly referenced!
The –ruby flag in the previous command installed the latest version of ruby. You can see that it has changed by checking for the version again:
ruby 2.1.3p242 (2014-09-19 revision 47630) [x86_64-darwin14.0]
Again, based on when you read this post and run these commands, your versions may be different.
Here are some default commands to get you started with RVM:
This will show you the ruby executables (also called rubies) installed on your machine.
rvm list known
This will show you the rubies you can install
rvm install [insert ruby version number]
This will install a specific version of ruby to your machine
rvm install 2.0.0
rvm use [insert ruby version number] –default
This will make sure that a specific version of ruby is used every time you open a terminal window
rvm use 2.0.0 --default
rvm gemset list
This will list all the gemsets for your current ruby version
rvm gemset create [insert gemset name]
This will create a gemset in your current ruby version
rvm gemset create my-gemset
rvm use [insert ruby version number @ gemset name] –default
This will make sure a specific version of ruby is loaded every time AND at a specific gemset
rvm use 2.0.0@my-gemset
Now. What do you need to do in order to get started with Rails? Well, to be honest, there is some discussion as to whether or not gemsets are even required with Bundler. Obviously they are more important if you are developing a Ruby project without Bundler. So, for me, I find setting a ruby version is all I need.
Using RVM you have the ability to manage different ruby versions, what gems are included with each one and you’re not cluttering up the built in ruby with all your various project gems.