Here are all the patterns a beginning Rails programmer needs to know about Gem and RVM. Once you have the few steps of the workflow memorised, they will be second nature to you.
First we have to be able to confidently use gems. But it is safer never to install gems until RVM is set to use a gemset. These commands are listed before any RVM commands because they can be used without RVM -- but if you are going to do much Ruby work, you will be better off using these only after creating gemsets to hold the gems you install.
$ gem install foo
$ gem uninstall foo
$ gem list
SAFETY FIRST: Use a gemset to store your gems. Installing a gem system-wide can trip you up if you somehow forget to work inside a gemset.
$ rvm list # Find current and other installed versions of Ruby
$ rvm current # Tell the current version of Ruby and the current gemset
$ rvm gemset list # List the current combo of Ruby and gemset and all other Ruby-gemset combos
$ rvm install ruby-1.9.3-p484 # Install a version of Ruby
$ rvm --create [email protected] # Create a Ruby-gemset combo
$ rvm [email protected] --create # The same thing
$ rvm [email protected] # Use the Ruby-gemset combo
$ rvm system # Use the system's version of Ruby (not what you usually want!)
Create one gemset like '[email protected]' and set it to RVM's default like so:
$ rvm install ruby-1.9.3-p484
$ rvm --create [email protected]
$ rvm --default use [email protected]
Following this procedure just one time will save you frustration in a situation where you need your usual combination of versions of Ruby and Rails and yet needed to install a later version of Rails previously for some other project. Install only the version of Rails you usually need in the rails3.2.14 gemset.
Somehow I got my [email protected] gemset into a state where Rails 4.0.1-beta1 was being used and I couldn't get around this simply. After lots and lots of searching I discovered 2 things:
- By default, running rails will pick up the latest version available in the environment, so if there are 3 versions of rails in a gemset, and Rails 4 is one of them, running 'rails new foo' will create a Rails-4 app.
- Just running 'gem remove rails' and telling Gem to remove a Rails 4 version will not completely remove that version of Rails! It will also be necessary to remove the same-versioned Railties and any other gems that depend upon that version of Railties (probably including coffee-rails, rails-observers, and sass-rails).