Switching from rbenv to postmodern’s ruby-install and chruby

I’ve seen many people switch over from rvm and rbenv to ruby-install and chruby. They are both small and simple tools to install ruby versions and switch between them.

Uninstalling current tools

Start by getting rid of your current tools. I’m on OS X and I’ve installed rbenv, ruby-build and a few other rbenv extensions through homebrew. I start by uninstalling them using homebrew.

$ brew uninstall --force rbenv rbenv-gem-rehash rbenv-gemset ruby-build

Also remove any rbenv specific stuff from your shell init file and $PATH. It’s possible to migrate seamlessly from rbenv to chruby but I preferred to start clean.

$ rm -rf .rbenv

Installing ruby-install

Then install ruby-install according to instructions. In my case using homebrew.

$ brew install ruby-install

Once that finished I just wanted the latest stable version of ruby for my system.

$ ruby-install ruby

This will install the latest stable ruby version into ~/.rubies. To install a specific version of ruby just add the version number.

Installing chruby

Next up install chruby according to instructions. I installed it using homebrew.

$ brew install chruby

If you’re keeping your old ruby installations then refer to the migrating instructions. I wasn’t so all I have to do is add the following lines to my shell startup script, ~/.zshrc.

source /usr/local/opt/chruby/share/chruby/chruby.sh
source /usr/local/opt/chruby/share/chruby/auto.sh

Note that the second line is optional and only needed if you use .ruby-version files, which I do. Then activate chruby.

$ source ~/.zshrc

I added a .ruby-version in my home directory to tell chruby to use the version I just installed

$ echo "ruby-2.3.0" > ~/.ruby-version

Then run ruby -v to confirm it worked.

$ ruby -v
ruby 2.3.0p0 (2015–12–25 revision 53290) [x86_64-darwin15]

For existing projects all that is needed is to install the ruby version required and use .ruby-version to tell chruby to use it. You’ll need to reinstall any gems as well. I did this for a rails project running ruby 2.2.3.

$ ruby-install ruby 2.2.3
$ echo "ruby-2.2.3" > .ruby-version # if you don't have one already
$ gem install bundler
$ bundle install

Now it’s possible to install ruby versions and change between them. That’s all I need. Both ruby-install and chruby are small and simple, they do one thing and they do it well, and the source code is short and easy to get your head around.

Feel free to connect with me on Twitter or visit my website for more information about me.