Installing rbenv on Raspberry Pi

Note: This article assumes a working knowledge of rbenv.

Installing rbenv (a Ruby version manager) on a Raspbian-based Raspberry Pi is a bit difficult because the base Debian ruby-build package does not provide you with an up-to-date list of Ruby versions.

To workaround this issue, you can easily install ruby-build yourself, instead of relying on the official Debian packages. I'm not a fan of the official rbenv package in the Debian repositories because it tries to install too many things (namely Ruby 1.8 for some reason), and I also don't like to install rbenv system-wide, so let's start by installing rbenv to our local user.

git clone https://github.com/sstephenson/rbenv.git $HOME/.rbenv

This will download the Git repository for the rbenv project into your home directory in a hidden subdirectory. rbenv doesn't come with a way to install Ruby version (oddly) which is why the ruby-build plugin is used. Then a directory is needed to hold the ruby-build plugin for rbenv.

mkdir $HOME/.rbenv/plugins
git clone https://github.com/sstephenson/ruby-build.git $HOME/.rbenv/plugins/ruby-build

You will need to add the rbenv binary path to your PATH as well as initalize rbenv everytime you start a new shell. In Bash, you add the following to your .bashrc file:

export PATH=$HOME/.rbenv/bin:$PATH
eval "$(rbenv init -)"

Now to install the latest Ruby version (2.2.0, as of this writing), we do the following:

rbenv install 2.2.0 --verbose

The reason I use --verbose is because rbenv does not provide enough detail during installation in case things stall or go wrong. This flag shows everything and will alert you to its progress. On my Raspberry Pi (Model B), the installation took around 3 hours, spending most of its time in the compilation and RDoc-generation phases.