Skip to content

Instantly share code, notes, and snippets.

@tomelam
Last active August 29, 2015 13:56
Show Gist options
  • Save tomelam/9032891 to your computer and use it in GitHub Desktop.
Save tomelam/9032891 to your computer and use it in GitHub Desktop.
Gem (aka Rubygems) and RVM Patterns

Gem (aka Rubygems) and RVM

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.

The Absolutely Most-Basic Gem Commands

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

The Absolutely Most-Basic RVM Commands

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!)

STRONG ADVICE

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.

How To Completely Uninstall Rails 4 from a 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).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment