---
title: Using rbenv to Manage Rubies and Gems
teaser:
tags: web,ruby
author: Laila Winner
published_on: 2013-04-06
---

We recently switched from <abbr title="Ruby Version Manager">RVM</abbr> to [rbenv][1] for managing Ruby versions.

> "Make each program do one thing well." - Tenet #2 of [The UNIX Philosophy](http://amzn.to/ZoqcHL)

## Why consider switching to rbenv

The UNIX philosophy espouses an approach to software in which small, sharp tools are designed and used to address discrete needs. By this standard, <abbr title="Ruby Version Manager">RVM</abbr> simply does too much. <abbr title="Ruby Version Manager">RVM</abbr> is responsible not only for changing Ruby versions, but for installing rubies and managing gemsets, as well.

Breaking these responsibilities apart and selecting a tool for each job is a good alternative to using RVM. Along with rbenv, we’re using [Bundler][2] to manage gems (replacing gemsets) and [ruby-build][3] to install rubies.

## How our rbenv workflow works

- Uses ruby-build to install Rubies
- Relies on Bundler and its' [binstubs][4] to manage gems
- Uses [shims][5] to handle executable gems
- [Updates shims][6] upon receipt of the `rbenv rehash` command after new Ruby executables are installed (rehashing can be automated with the [gem rehash plugin][7])
- Installs everything to `~/.rbenv/`

## How to switch from RVM to rbenv

Check out our [laptop script][8] to see our process for installing rbenv, or follow the steps below.

If you’re a tmux user, be sure to kill all your tmux sessions before installing rbenv to prevent <abbr title="Ruby Version Manager">RVM</abbr> from polluting your environment.

In your root directory, remove <abbr title="Ruby Version Manager">RVM</abbr> from your system:

    rvm implode

Restart your shell to ensure you're beginning your rbenv installation in a clean environment:

    exec $SHELL -l

Next, install rbenv using homebrew:

    brew update
    brew install rbenv

Configure your bash or zsh profile:

    echo 'eval "$(rbenv init -)"' >> ~/.zlogin
    source ~/.zlogin

Install ruby-build and rbenv rehash gem using homebrew:

    brew install rbenv-gem-rehash
    brew install ruby-build

Install your preferred version of Ruby and set it as the global default:

    rbenv install 2.0.0-p353
    rbenv global 2.0.0-p353

Update to the latest Rubygems version:

    gem update --system

Install gems critical to Rails development, e.g.

    gem install bundler foreman pg rails thin --no-rdoc --no-ri

You can set project-specific Ruby and gem versions by running the `rbenv local` command within your project directory:

    rbenv local 2.0.0-p247

If you follow the steps above and find you're having issues with rbenv, check your `echo $PATH`. Most likely you're not seeing the appropriate `~/.rbenv` dir.

If so, you either haven't added the init to your zsh profile, or something else is mangling the path.

## Extras

- To ease the transition, install the [use plugin][9], which lets you run RVM-style commands with rbenv
- [rbenv-binstubs][10] is a handy plugin that allows you to omit `bundle exec` when you run commands

[1]: https://github.com/sstephenson/rbenv/
[2]: https://github.com/carlhuda/bundler/
[3]: https://github.com/sstephenson/ruby-build
[4]: https://github.com/sstephenson/rbenv/wiki/Understanding-binstubs
[5]: https://github.com/sstephenson/rbenv/#understanding-shims
[6]: https://github.com/sstephenson/rbenv/#rbenv-rehash
[7]: https://github.com/sstephenson/rbenv-gem-rehash
[8]: https://github.com/thoughtbot/laptop/blob/master/mac
[9]: https://github.com/rkh/rbenv-use
[10]: https://github.com/ianheggie/rbenv-binstubs
