How to Manage Your Ruby Installation with rbenv

Managing the whole development environment is often a lot of work. You need to get the right tools in the right version and the paths and other environment settings must all be right – or you go on an endless hunt for one problem after another. If you work with Ruby you should look at rbenv. This little helper lets you switch between different versions of Ruby and ensures that everything works as you expect.

 

Installation

You can install rbenv with one of those three options:

  1. Git
  2. Homebrew (on Mac only)
  3. rbenv-installer

The official documentation explains all three options and guides you through the installation. I used the basic Git export without any problems. It takes a little bit more work, but it allows you full control over what happens.

 

Installing a specific version of Ruby

With rbenv in place, you can check what versions of Ruby are available using this command:

This command shows you a near endless list of different versions you can choose from. It even includes different Ruby implementations like MRI, JRuby, Rubinius and TruffleRuby. If you found the version you need, you can install it using this command:

 

Switch between different versions of Ruby

When the installation succeeded, you can tell rbenv to use a specific version. If this version is the one you want to use all over your system, you can use the global command:

Sometimes you do not want to change the system wide version and only need it in the current terminal. In this case, you can use the local option:

You can check if the right version is active asking for the version of Ruby:

 

Updating rbenv and getting new Ruby versions

If you used Git for the installation, you need to do the updates on your own. That is done by a git pull in the directory you installed rbenv:

However, that only updates rbenv itself. Inside this directory is another Git repository, that you need to update when you want new versions of Ruby:

This part is a bit tricky and easy to forget. It takes a few rounds of updates until you remember that bit of extra work.

 

Conclusion

This little tool is a great help to manage your Ruby installation. It is especially useful when you need to upgrade Rails applications. With rbenv it only takes minutes to get the right version of Ruby that is compatible with the Rails version you try to install. If you work with different versions of Ruby you definitively should try rbenv.

2 thoughts on “How to Manage Your Ruby Installation with rbenv”

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.