Friday, August 2, 2013

Ruby Version Management: Using rbenv in favor of rvm

Objective


As I am still considering myself as a beginner with the Ruby programming language. I'd like to write a little "HowTo" on installing and managing the versions of the Ruby interpreter on my local machine as a personal reminder.

Since I always used the "Ruby Version Manager (rvm)" for doing the job, I decided this time to take the chance with ruby 2.0 and rails 4.0 to experiment with "Ruby Environment (rbenv)" which is also recommended on the Ruby on Rails homepage to be used as a substitute for rvm. With using rvm in the past I also always got confused by system installation using sudo and installation just for the current user. Hopefully, I can escape this mess using rbenv.

Prerequisites


At the moment, I am sitting in front of my MacBookAir with an installed Mountain Lion OS X (10.8.x) and only the default Ruby version running, which is "ruby 1.8.7".

To start the process of installation, I moved on from the RoR homepage to

https://github.com/sstephenson/rbenv

where I expected to find some instructions to start with.

Yeah! The documentation there seems to cover all the aspects of rbenv. So I'll just leave it by the link to the documentation and only write about my experience installing rbenv and ruby 2.0.

Installation


Additional Prerequisites


After reading the instructions, I decided to install rbenv via the source distribution on github instead of using homebrew. While starting the process I figured out that I even didn't install the Mac Vi Editor "mvim" yet, but still had an "alias vi='~/ApplicationsMacVim-snapshot63/mvim'" in my "~/.bash_profile". Must have been some leftover from a previous MacOS X installation. Therefore I quickly jumped to the developers site of macvim and installed the proper version. After adjusting the 'alias-command' I could proceed with installing rbenv.

Note: Ensure that after changing the "alias" you restart your shell or at least re-read your "~/.bash_profile" by the command "source ~/.bash_profile". With the command "alias" you can list all "aliases" and check if everything is correct.

To avoid confusion in the next following paragraphs "Step X" always refers to the number of the step from the original instructions of installing rbenv.

Step 2


I also couldn't follow Step 2 of the installation process, because I am already using a customized ~/.bash_profile file and the instructions just will put another export statement for the $PATH variable at the end of the ~/.bash_profile. Therefore, I adjusted my ~/.bash_profile manually by exchanging the following line

export PATH=${PATH}:${HOME}/bin

by

export PATH=$HOME/.rbenv/bin:${PATH}:${HOME}/bin

Step 3


I also decided to add Step 3 handcrafted, keeping in mind that the 'export PATH=...' must appear earlier in the file than 'eval "$(rbenv init -)"'.

Step 5


At Step 5, I switched over to the installation guide for ruby_build plugin, which surprisingly was written by the same author as rbenv, Sam Stephenson. The installation as a plugin for rbenv worked like a charm, so I thought I am able to install ruby 2.0 now.

Hum, but how do I have to choose the ruby version exactly?

Just typing "rbenv install" without any parameter gives an overview about the options that can be used with the install command and as I already expected, there was an option to list all available Ruby versions: "rbenv install -l" which gave me ...

2.0.0-dev
2.0.0-p0
2.0.0-p195
2.0.0-p247
2.0.0-preview1
2.0.0-preview2
2.0.0-rc1
2.0.0-rc2

Oops! It seems that I am doomed!

Which version to install?
What is this versioning scheme "dev", "p#", "preview#", "rc#" all about?

I just wanted to install the latest stable version.

After some investigation, I brought light into the dark:

name-suffix meaning
dev# development branch
p# stable version at patch level #
preview# preview version no #
rc# release candidate no #

So, I finally decided to pick version 2.0.0-p247:

$ rbenv install 2.0.0-p247

Surprisingly, the command started to install openssl first on my mac.

Downloading openssl-1.0.1e.tar.gz...
-> https://www.openssl.org/source/openssl-1.0.1e.tar.gz
Installing openssl-1.0.1e...
Installed openssl-1.0.1e to /Users/cschmidt/.rbenv/versions/2.0.0-p247

This unfortunately was not mentioned in any place of the instructions, but gladly it is just installed within the "~/.rbenv" directory itself and therefore does not mess up the system. Finally I got ...

Downloading ruby-2.0.0-p247.tar.gz... -> http://ftp.ruby-lang.org/pub/ruby/2.0/ruby-2.0.0-p247.tar.gz Installing ruby-2.0.0-p247... Installed ruby-2.0.0-p247 to /Users/cschmidt/.rbenv/versions/2.0.0-p247

Nicely ruby 2.0.0 can be installed using the clang compiler and does not need to have gcc installed on your Mac, as it's predecessor versions e.g. "ruby 1.9.2"

So, I assume, that ruby 2.0 is installed now. Let's do a last check ...

$ ruby -v

ruby 1.8.7 (2012-02-08 patchlevel 358) [universal-darwin12.0]

Aha, ... ok, there seems to be some configuration left.

Configuration


As I wanted to do this just quick and system wide

$ rbenv global 2.0.0-p247

Check again ...

$ ruby -v

ruby 2.0.0p247 (2013-06-27 revision 41674) [x86_64-darwin12.4.0]

Finally done.

6 comments: