FUN WITH LINUX

Ruby: Managing multiple ruby-versions for a single user

12 September 2015

rbenv is a nice light-weight tool to switch between different ruby-versions. It’s cool because we can also create a directory with a ruby-installation in it and install all our modules inside this installation-directory. In that way we don’t have to mix our system-ruby-installation with some gem-modules.

rbenv is easily to install on debian-systems:

apt-get update && apt-get install rbenv

Now we can download the sources of ruby, compile it and install it into a custom installationdir:

./configure --prefix=$HOME/.rbenv/versions/2.1.3
make
make install

Or we just install a ruby-version via ruby-build:

ruby-build 1.9.2-p290 $HOME/.rbenv/versions/2.1.3

Now let’s rehash rubyenv:

rbenv rehash

We need to initialise rbenv if we open a shell, so lets put the following line to our $HOME/.bash_profile:

eval "$(rbenv init -)"

We could change our global ruby-version to our freshly build 2.1.3-version:

dr@tardis> rbenv global 2.1.3

So let’s open a new shell and check our ruby-versions:

dr@tardis> rbenv versions
  system
* 2.1.3 (set by /home/dr/.ruby-version)

Now we are using our custom ruby-version:

dr@tardis> ruby --version   
ruby 2.1.3p242 (2014-09-19 revision 47630) [x86_64-linux]

If we install gem-modules, they will be installed in our custom ruby-directory.

I really love this tool. It’s simple and it helps a lot. For further informations please check out the website of this project: https://github.com/sstephenson/rbenv/blob/master/README.md The documentation there is very good!

[ Programming  Sysadmin  Ruby  ]
Except where otherwise noted, content on this site is licensed under a Creative Commons Attribution 3.0 Unported License.

Copyright 2015-present Hoti