Home / Community
Home / Community

rbEnv alias version

D3177da7794ac3ce603d65b33bf4a981by Gonzalo Fernandez|

Aug 03, 2012


So now you are using rbEnvgroovy! :)

I've been using it for a while, and I must say it's been a great change.
I don't want to continue with the Ruby drama/war between RVM vs rbEnv, but I have been loving almost everything about rbEnv.

My only two "issues" right now are:

  • Gem binaries not available after installing. rbenv rehash fixes this :)
  • Ruby versions with minor patch levels only (example: 1.9.3-p194 instead of 1.9.3 only)

The second issue is especially annoying because Ruby is updated often (thankfully), so the version I will have installed in my machine will be probably different from the versions installed in the rest of the world.

I like to include a .rbenv-version with the exact Ruby version to use in my projects:

$ cat .rbenv-version 

This file IS tracked in the Git repository, so I really need to avoid having a different patch level to avoid forcing other developers to have more than one 1.9.3 versions.


For the impatients, create an alias for your current Ruby version (1.9.3-p1):

ln -sf "$HOME/.rbenv/versions/1.9.3-p194" ~/.rbenv/versions/1.9.3

Prerequisite: install the Ruby version that you want to use, 1.9.3-p194 in my examples: rbenv install 1.9.3-p194

Create rbEnv aliases

My solution for this, is to create an alias for the more general Ruby version, and point it to the "real" version installed.

ln -sf "$HOME/.rbenv/versions/1.9.3-p194" ~/.rbenv/versions/1.9.3

After this, the Ruby versions that I have currently "installed" are:

$ rbenv versions
* 1.9.3 (set by /Users/chalofa/repos/ci/retrospectus/.rbenv-version)

You can see how the 1.9.3 alias appears in the list, just as if we installed it with rbenv install.

Use alias version as default

Now, why don't we make that Ruby version our default?

Execute this in your shell:

$ rbenv global 1.9.3
$ ruby -v
ruby 1.9.3p194 (2012-04-20 revision 35410) [x86_64-darwin11.4.0]

Track the .rbenv-version file

This will probably cause some controversy, but as I told before, I like to keep my .rbenv-version tracked in the SCM, git in my case.

The benefits will be that all users will be able to use the same Ruby version that you are working with.

On the other side, an issue would be that you will need to install different Ruby versions (with different patch levels if you don't use the alias).
This is solved using this small trick.

So, instead of using rbenv local 1.9.3-p194 or rbenv local 1.9.3-p194, I can use a more general approach: rbenv local 1.9.3, which will point to p194 or the version I have installed in my system.

blog comments powered byDisqus