Couple weeks ago I switched from RVM to rbenv because I think it’s a cleaner and faster way to handle Ruby versions. It is more respecful of the Unix philosophy.

It worked like a charm right after the installation but Pow wasn’t working anymore. There’s just a little trick to know.

So let’s have a reminder about rbenv and see how to make it work with Pow.

Daily use

I’m running Mac OS X and chose to use HomeBrew as my package manager. Let’s install rbenv and Pow.

Rbenv Install

$ brew update
$ brew install rbenv
$ brew install ruby-build
$ brew install pow

You’re now ready to install your rubies. Be sure to uninstall RVM first if you installed it. RVM overwrites many shell commands and would cause troubles to rbenv if there are both installed:

$ rvm implode

Add this line to your .bash_profile or .zshenv :

export RBENV_ROOT=/usr/local/var/rbenv
if which rbenv > /dev/null; then eval "$(rbenv init -)"; fi

Open up a new shell and you’re ready to go.

Rubies install

First you can list candidates for installation:

$ rbenv install

Install the one you need:

$ rbenv install 1.9.2-p290

Check installed versions:

$ rbenv versions

Specify a default Ruby version to use system-wide:

$ rbenv global 1.9.2-p290

Specify an other version to use in a given directory / project:

$ cd Code/foo
$ rbenv local ree-1.8.7-2011.03

You can also set a ruby version to use in a shell for its lifetime:

$ rbenv shell 1.9.3-p0

Gemsets

rbenv users tends to think that Bundler is the way to go to handle project dependencies. Why use a gemset when the project itself can be the gemset. If you have a Gemfile then you can do:

$ bundle install --path vendor/bundle

Gems will be installed in vendor/bundle project directory. Be sure to exclude this dir from your SCM.

You can automate this behaviour by using Bundler config file. Edit ~/.bundle/config like so:

---
  BUNDLE_PATH: vendor/bundle

If you really need and want something similar to RVM gemsets, take a look at rbenv-gemset.

Using Pow with rbenv

Update: Note for users of Pow < 0.4.2 only. As of Pow >= 0.4.2 the following problem doesn’t exist anymore since Pow now loads user’s environment variables properly for Zsh users.

I ran into a problem when I tried to access my projects using Pow. Pow was getting the request but crashes due to gems missing or bad ruby version.

Pow doesn’t know anything about rbenv so you need to tell him about the right PATH to be able to use rbenv.

Edit ~/.powconfig like this:

export PATH=$(rbenv root)/shims:$(rbenv root)/bin:$PATH

Be sure to restart pow after editing this file.

Now you have rbenv and Pow up & running!

Leave a Comment