Replacing RVM with rbenv in OS X

For several years, I’ve been using RVM to manage and install different versions of Ruby and gemsets on my system. For anyone using Ruby, it’s an essential tool in making development much easier. It helped me greatly in managing different versions of Ruby and different gemsets to make sure that my development environment always matches my production environment.

But recently, I’ve switched over to rbenv, another popular Ruby version manager. I find myself no longer using RVM to install newer versions of Ruby and managing different gemsets. There are now better tools for managing these tasks. Bundler is a much better tool for handling dependencies, and many gems these days are already using it. Starting a project is easy as as typing bundle install.

Why choose rbenv?

Rbenv is a lightweight Ruby version management tool. Compared to RVM, rbenv does not manage gemsets nor install different Ruby versions. These tasks are now better off handled by other tools as mentioned earlier.

Installing rbenv

To install rbenv, it’s very important to remove RVM first from your system because it is incompatible with rbenv. To do this, just type this command:

$ rvm implode

This will remove all installations of Ruby it manages and everything in ~/.rvm.

It is also important to keep in mind that you might also need to manually remove the following folders if they still exist.

/etc/rvmrc 
~/.rvmrc

Finally, you might also need to delete or comment out any lines that exist in .bashrc and .bash_profiile that contains RVM-specific settings. Once removed, rbenv can now be installed by typing the following commands:

$ brew update
$ brew install rbenv ruby-build

These commands will install rbenv and ruby-build using the Homebrew package manager for Mac OS X. The ruby-build is a plugin that handles rbenv install command to compile and install different versions of Ruby on UNIX-like systems.

Afterwards, you need to add rbenv to the PATH environent:

echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.bash_profile  
echo 'eval "$(rbenv init -)"' >> ~/.bash_profile 

These commands will append the necessary paths required by rbenv to be recognised by your system. You might need to restart your terminal after updating these files.

Installing different Ruby Versions

You should now be able to run the following commands:

# list all available versions:
$ rbenv install -l

# install a specific Ruby version:
$ rbenv install 2.2.2

As an alternative, you can also download and install Ruby manually by installing it in a subdirectory in ~/.rbenv/versions/. Each subfolder in this directory will be treated as a separate Ruby version.

To verify which Ruby version you are currently using, just type:

$ ruby -v

This should output something like

ruby 2.2.2p95 (2015-04-13 revision 50295) [x86_64-darwin14]  

Final Thoughts

Now, you can start coding again and make cool shit.