Over the last day or so I’ve been slowly moving my ruby projects over to using rbenv instead of RVM. There’s nothing inherently wrong with RVM, but I do lots of interesting things with my shell that, when combined with my tmux setup, seems to always be giving me flak.
So at the recommendation of a friend, I sat down with
rbenv for a couple of hours, and these are my notes from that experience.
Typically, I would not make a change so drastically, but I found the process of converting to be fairly painless and simple enough for me to go back to if need be without much fanfare. The process for me was to …
- Remove any source references to RVM scripts in my .bashrc and .bash_profile files
- Remove any path modifications that include the RVM bin dir
- Use homebrew to install rbenv (alternatively, you could clone the repository1 into ~/.rbenv
- Add the following into my .bashrc
If all went well above, we should have a working rbenv installation. Now let’s take a look at the rubies currently available –
I only have a single ruby version install initially, but with the help of the ruby-build2 plugin (available via hombere), I get access to the
rbenv install command where I can install new versions of ruby.
In this case, my system ruby is version 2.0.0-p481 (
ruby -v). This is too new for all my work, since I do a good deal with Puppet on RHEL6 which ships with 1.8.7-p374. Let’s start by installing that version –
Now looking at the versions available to us, we see –
Activating a Ruby
I typically activate rubies in two ways. First and foremost, when I’m switching between rubies for testing I used to use
rvm use $version to get the ruby I want. With rbenv, this becomes
rbenv shell $version.
The second way I choose rubies is by setting my ruby version in the .ruby-version file in my project directory. Fortunately, this does not really change and I can mostly leave it alone3.
For more information on how rbenv chooses a ruby version, see the project’s README section4 on the subject
The next post will dive into the differences in gemset management between RVM and rbenv, as well as some useful plugins that make rbenv a better tool all around.
rvm conviently allows you to select which gemset you want to use within the .ruby-version file. rbenv on the other hand does not even support gemsets without the help of the rbenv-gemset5 plugin. With it, you need only move the gemset information into the .ruby-gemset file. Part 2 will go into more detail about gemsets. ↩