How to install rbenv on Linux Mint 17.1

Last year I wrote about installing rbenv on Linux Mint 16. Back then the installation process as described on the project’s Github page didn’t work for me and, after much frustration,  I ended up installing an older version of rbenv from the repositories.

Recently, I had to reinstall my operating system (upgrading to Mint 17.1) and decided to give the rbenv installation process another try. I’m happy to say that it worked entirely as expected and within a matter of minutes I had two Ruby versions installed on my system and could switch between them at will.

Nonetheless, this still involved a little preparation and several steps which I want to summarize in this post.

So, Let’s Get Started!

As we will need to clone the rbenv repository, the first thing to do is ensure that git is installed on your system. To do this open a terminal and type:

git --version

If this prints out a version number, it’s all good. If it doesn’t you’ll need to grab git from the repositories:

sudo apt-get install git

The developers of rbenv recommend running the following command before installing and using rbenv itself:

sudo apt-get install autoconf bison build-essential libssl-dev libyaml-dev libreadline6-dev zlib1g-dev libncurses5-dev libffi-dev libgdbm3 libgdbm-dev

This will install everything necessary to create a sane build environment.

Next we need to clone the rbenv repo to our home directory:

git clone https://github.com/sstephenson/rbenv.git ~/.rbenv

Then add ~/.rbenv/bin to our $PATH for access to the rbenv command-line utility:

echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.bashrc

If you are following along with a different Linux distro, you will have to modify ~/.bash_profile or ~/.zshrc accordingly.

After that, add rbenv init to your shell to enable shims and autocompletion:

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

Finally, restart your shell:

exec bash

You can check if all has gone well with the following command:

type rbenv

This should output:

rbenv is a function
rbenv () 
{ 
...
}

Congratulations! You have now successfully installed rbenv.

Install ruby-build

Now, a Ruby version manager is no good without a few Ruby versions to manage and the easiest way to compile and install different versions of Ruby on your system is with the aid of the ruby-build plugin.

The first thing to do is to install it. Like rbenv itself, it can be cloned from its Github repo:

git clone https://github.com/sstephenson/ruby-build.git ~/.rbenv/plugins/ruby-build

Once it’s there, you can view available Ruby versions with the following command:

rbenv install --list

Choose the one you want and install it, thus:

rbenv install <version_number>

This will take a while (depending on your system). The Ruby version will be installed to .rbenv/versions/version_number.

Select the previously installed version:

rbenv global <version_number>

And that’s all there is to it:

jack@friendly ~ $ irb
irb(main):001:0> puts "Woo hoo!"
Woo hoo!
=> nil

Reference: Chruby and Rbenv Tips and Tricks

I hope this proves useful for people. If you have any questions or observations, I’d be glad to hear them in the comments.

If you made it this far then you might consider following me on Twitter:

I'm on Twitter:

Categories