Installing Rubinius with Rbenv

by Andrew Stewart
published September 6, 2013

EDIT: (2013-09-27) - Updated to reflect that RBENV_VERSION is now ‘rbx’ (at least for me). Check the value yourself if it isn’t working.

(Disclaimer: These steps may not work for you. This is just what got my system working. If you have any feedback or step suggestions, let me know.)

While gearing up for a new release of the gitnesse gem, I noticed the RSpec suite was failing in JRuby and Rubinius on Travis. To fix this, I had to install both Rubies on my system.

Let’s start by installing them through ruby-build. Easy enough, right?

$ rbenv install jruby-1.7.4
Downloading jruby-1.7.4.tar.gz...
-> http://jruby.org.s3.amazonaws.com/downloads/1.7.4/jruby-bin-1.7.4.tar.gz
Installing jruby-1.7.4...
Installed jruby-1.7.4 to /Users/stewart/.rbenv/versions/jruby-1.7.4

Ok, That went well. Now let’s install Rubinius!

$ rbenv install rbx-2.0.0-dev
Downloading yaml-0.1.4.tar.gz...
-> http://dqw8nmjcqpjn7.cloudfront.net/36c852831d02cf90508c29852361d01b
Installing yaml-0.1.4...
Installed yaml-0.1.4 to /Users/stewart/.rbenv/versions/rbx-2.0.0-dev

Cloning https://github.com/rubinius/rubinius.git...
Installing rubinius-2.0.0-dev...

BUILD FAILED

Inspect or clean up the working tree at /var/folders/6n/pd5r9l_x73s6vv656xzy1rph0000gn/T/ruby-build.20130906193908.56657
Results logged to /var/folders/6n/pd5r9l_x73s6vv656xzy1rph0000gn/T/ruby-build.20130906193908.56657.log

Last 10 log lines:
  --without-fibers           Disable fibers
  --with-dtrace              Enable dtrace
  --without-dtrace           Disable dtrace

Help!
  --show                     Print the current configuration and exit
  -V, --verbose              Print additional info
  -h, --help                 Show this message

Unrecognized option: --with-readline-dir=/usr/local/opt/readline

Ah. That’s not quite what I was expecting. We can still built it manually, though, since rbenv doesn’t really care how the Ruby gets installed:

$ git clone https://github.com/rubinius/rubinius.git && cd rubinius
$ ./configure --prefix=~/.rbenv/versions/rbx-2.0.0-dev
$ rake install

After this is done, we can switch over to using Rubinius:

$ rbenv shell rbx-2.0.0-dev

Alright. Now let’s try installing Bundler, so we can install RSpec and run the tests:

$ cd ~/dev/project

$ gem install bundler && rbenv rehash
Fetching: bundler-1.3.5.gem (100%)
Successfully installed bundler-1.3.5
1 gem installed

$ rbenv which bundle
rbenv: bundle: command not found

The `bundle' command exists in these Ruby versions:
  1.9.3
  1.9.3-p194
  2.0.0
  2.0.0-p247
  jruby-1.7.4

It turns out that Rubinius uses a different install path for gem binaries than most other Rubies, so rbenv can’t find them by default. Luckily, there’s a plugin that fixes that. Let’s install it:

$ mkdir -p ~/.rbenv/plugins
$ cd ~/.rbenv/plugins
$ git clone https://github.com/rmm5t/rbenv-rbx.git

This plugin helps, but it’s not compatible with the most recent (as of this writing) version of Rubinius. We can fix that by changing the relevant files:

~/.rbenv/plugins/rbenv-rbx/etc/rbenv.d/rehash/rbx.bash
make_shims ../versions/rbx-2*/gems/bin/*
~/.rbenv/plugins/rbenv-rbx/etc/rbenv.d/which/rbx.bash
if [ ! -x "$RBENV_COMMAND_PATH" ] && [[ $RBENV_VERSION =~ rbx ]]; then
  export RBENV_COMMAND_PATH="${RBENV_ROOT}/versions/${RBENV_VERSION}/gems/bin/${RBENV_COMMAND}"
fi

And now we’re off to the races:

$ cd ~/dev/project
$ rbenv which bundle
/Users/stewart/.rbenv/versions/rbx-2.0.0-dev/gems/bin/bundle

While I was writing this, Brian tweeted at me, letting me know that I should use Chruby instead of Rbenv. Currently rbenv is too integrated into my workflow and shell to switch over to chruby on a whim, but I’ll have to give it a shot at some point and see if it makes it easier to get up and running with multiple Rubies.

UPDATE: It does.