812law
Last Updated: February 25, 2016
·
1.586K
· jonahoffline
4693d7cfa88635d430c0de9a92f8dd84

RVM for your Ruby projects

While doing some pair-programming with a friend of mine, I noticed he had RVM installed but only used one gemset for everything. As a result, his machine was slow and polluted with old gem versions. You could say that it was almost a mirror of Rubygems. I wondered how many ruby developers had the same problem so I decided to share this.

Installing RVM

If you have never used RVM, you've been missing out. It won't do the dishes or clean your room, but it will make you happier. RVM allows you to easily install, manage, and work with multiple ruby environments. Avoiding version conflicts and maintaining any ruby project, gem, or Rails app organized is now a breeze.

Let's get it out of the way and install it along a stable version of Ruby.

$ \curl -L https://get.rvm.io | bash -s stable --ruby

Depending on your internet connection and computer, it will take a few minutes. Once that's done, you will need to reopen your shell window or run:

$ source ~/.rvm/scripts/rvm

Let's verify that RVM is loaded and that everything is installed correctly.

$ rvm current

You should now get a Ruby version (e.g., ruby-2.0.0-p247). If you didn't, run rvm notes.

Using RVM to organize your projects

Instead of globally sharing one gemset for all projects, let's create one for our imaginary Quantum Kittens Rails App.

Just enter the directory and run:

$ rvm --create --ruby-version ruby-2.0.0-p247@quantum_kittens

The command will not output anything, but if we run ls -a you will notice there are now two files in the directory.

.ruby-version
.ruby-gemset

From now on, RVM will automatically change into that ruby version (ruby-2.0.0-p247) with any gems you install to its self-contained gemset (quantum_kittens) every time you enter that directory. You should check these two files into your source control.

Other useful RVM commands

This article would not be complete without a few of the most used RVM commands.

To verify the current version and gemset:

$ rvm current

To get a list of gemsets:

$ rvm gemset list

To get a list of all the installed versions of ruby:

$ rvm list  

To view available versions of ruby to install:

$ rvm list known

To install another ruby version:

$ rvm install rbx-head

To set a default ruby with a new gemset:

$ rvm --create --default use rbx-head@kawaii_gems

To remove a gemset:

$ rvm gemset delete evil_gems
Say Thanks
Respond

4 Responses
Add your response

8237
1b287bf5274a4f59d5742cc2e9a8f76a

Nice tutorial man, sure it's helpful :)

over 1 year ago ·
8238
4693d7cfa88635d430c0de9a92f8dd84

Thanks! Glad it helped! :)

over 1 year ago ·
8560
5e6ceef905d14ade228ea22c445d57bc

Why would having many gems slow down a machine?

over 1 year ago ·
8564
4693d7cfa88635d430c0de9a92f8dd84

Well, when not using gemsets, bundler's dependency resolver algorithm (https://codeclimate.com/github/bundler/bundler/Bundler::Resolver) will take more time to finish. Add to this the fact that when you remove a gem dependency from your Gemfile, bundler will update your Gemfile.lock, but it won't uninstall it. Your system just keeps getting polluted with more gems you aren't even using. Hard drive space is wasted.

over 1 year ago ·