(X)Ruby on the Mac


_Update Aug. 2010_

The “RVM installer”:http://rvm.beginrescueend.com/rvm/install/ should be prefered over installation via gem:

bash < <( curl http://rvm.beginrescueend.com/releases/rvm-install-head )


If you are a Mac user and a Ruby developer you probably ran into issues with custom Ruby installations and had troubles with Gems like these:

* "How to fix that Rubygems mess on Leopard":http://blog.carlmercier.com/2007/12/14/how-to-fix-that-rubygems-mess-on-leopard/
* "Installing Ruby, RubyGems, and Rails on Snow Leopard":http://hivelogic.com/articles/compiling-ruby-rubygems-and-rails-on-snow-leopard/
* "How do I install the mysql ruby gem under OS X 10.5.4":http://stackoverflow.com/questions/41134/how-do-i-install-the-mysql-ruby-gem-under-os-x-10-5-4
* [...neverending list of links...]

h2. Using MacPorts

There are a lot of people that recommend using "MacPorts":http://www.macports.org/ for installing a custom Ruby version, but there are a lot of "issues with this approach":http://lmgtfy.com/?q=macports+ruby+error too. If you did manage installing the Ruby version of choice, you might run into "issues using TextMate":http://old.nabble.com/Subversion-Hangs-When-I-Try-to-Commit-td15208705.html or other tools, that depend on the default OS X Ruby (I think that I had ALL the problems one could have, but this might be an exaggeration).

h2. Custom (X)Ruby Versions

The next problem arises if you want to use different versions of Ruby or even *different implementations/runtimes* (EVIL666) like "JRuby":http://jruby.org/, "MacRuby":http://www.macruby.org/ or "Rubinius":http://rubini.us/.

I am currently using:

* Ruby 1.8.6 for integration with "Heroku":http://heroku.com/
* Ruby 1.8.7 for daily usage
* Ruby 1.9.1 for a fast Ruby experience
* MacRuby for playing around and avoid looking at verbose Objective-C code
* JRuby for "Buildr":http://buildr.apache.org/

There are some simple approaches to fix this mess. MacPorts and JRuby provide different binaries to run like _ruby18_, _ruby19_ or _jgem_, but this is error prone and confusing. I was always installing Gems to the wrong Ruby environment and there were always conflicts with scripts and tools looking for the actual Ruby binary.

Since this did not work out quite well I started to wire the path tightly in the _.profile_ file to include just the right Ruby and Rubygems binary. This had the drawback that I had to close terminals for every switch. So I started writing bash scripts manipulating the path directly, which worked well, but was unconvenient.

Most of the Ruby versions are not stable. Ruby 1.9 is under development, JRuby has frequent compatibility and performance releases and MacRuby is kind of an an "Alpha".
As far as I am concerned, I always want to use the *latest stable* release of these distributions! Using MacPorts you often just get *some* release, so you have to compile stuff yourself. Doing so is time consuming and painful...

h2. RVM to the rescue

Some weeks ago I stumbled over "RVM (Ruby Version Manager)":http://rvm.beginrescueend.com/, which can be installed as a Gem to the standard preinstalled OS X Ruby. RVM provides some neat features and does exactly what I want. It provides a simple interface to manage Ruby distributions and does some clever stuff organizing local Gems.

Right now I am using the preinstalled OS X Snow Leopard Ruby distribution with RVM and no ports:

# check that you are running default Ruby
ruby -v
=> ruby 1.8.7 (2008-08-11 patchlevel 72) [universal-darwin10.0]

# update your OS X Rubygems
sudo gem update --system

# check Gem version
gem -v
=> 1.3.5

# install RVM as a Gem to the defaut OS X Ruby
sudo gem install rvm

# run RVM installation
# follow the installation instructions (add RVM to the $PATH etc)

# open new terminal and check RVM version
rvm --version
=> rvm 0.1.0 by Wayne E. Seguin ([email protected]) [http://rvm.beginrescueend.com/]

# have a look at the manual
rvm --help

# install a (X)Ruby version
rvm install jruby

# see what is installed
rvm list

# see some more information
rvm info

# use a (X)Ruby version
rvm use jruby

# install a gem for the current (X)Ruby
gem install buildr

# install a gem for all Rubies under RVM control
rvm gem install -v=0.6.9 savon

# flip back to default Ruby
rvm system

Cut Rubies with ease...

4 thoughts on “(X)Ruby on the Mac

  1. Pingback: Ruby in Java, Java in Ruby, JRuby or Ruby Java Bridge? | #nofail

Comments are closed.