Skip to main content

Installing (painlessly) Ruby 1.9.3 into Mac OS X

Update: Nov. 2012. I no longer recommend rbenv, I now recommend RVM (ruby version manager) since both require Xcode to function. And the latest JRuby (1.7.0) now defaults to 1.9.3 and doesn't require the --1.9 switched to be passed or a JRUBY_OPTS variable set.
(I also updated the post to reflect the proper capitalization of JRuby vs. Jruby, which is incorrect.)
-----

Installing the latest version of Ruby on Mac OS X is a bit more complicated than it should be. There are no .dmg installers and the built in version 1.8.7 is quite old now.  There are various ways of installing ruby on a Mac and here is a list from the least painful to the most annoying.

  1. Using JRuby or MacRuby are the least painful way to install Ruby 1.9 to OS X. They come with their own .dmg installer, it's easy and fast. Unfortunately JRuby (although it includes 1.9) defaults to 1.8 so you have to go into your .bash_profile file and add a line there. See previous blog here. Note that because ruby is already installed on the Mac you'll have to use JRuby/MacRuby vs. ruby, jgems/macgems vs. gems and jirb/macirb vs. irb on the command line, and to run rails in JRuby it's the arcane jruby -S rails. I haven't gotten rails to run well with MacRuby yet, but MacRuby is the way to go for integration with the Mac. MacRuby plays well with Xcode too. But one thing both of these have against them: they're not 1.9.3, they only go to 1.9.2.
  2. Using ruby_build with rbenv mostly painless but there are a few snags I hit and below is an explanation on how I installed it and how to avoid the snags.
  3. Using RVM with Xcode. Rvm or the ruby version manager is the way to go on Linux but on the Mac it requires the gargantuan (and thankfully now free) Xcode to be installed. Once you have Xcode on board it should be easy sailings (mostly). Though if you use Netbeans watch out it has not so good interaction with rvm's rubies.
  4. MacPorts or HomebrewI haven't played around with these because they requires Xcode to install, but looks straight forward. Macports has an dmg installer. And Homebrew looks like it's even easier. Homebrew is actually written in ruby. There is also Fink but I haven't heard much about it. 
  5. Install from source (Painful! And no I haven't tried it). I've installed ruby from source on Ubuntu and the process was straight forward-ish but on the Mac I'm not so sure. My guess is that the new compiled ruby will go to /usr/local/bin instead of the /usr/bin/ where the normal Ruby is but I don't know. Also this requires Xcode installed and probably some interesting work on the path. Additionally compiling from source you'll have to worry about weather you have the right headers for x or y plugin. I ended up deleting my Ubuntu compiled Ruby because the it would not play with the gtk2 ruby gem. 


Recommended: ruby_build with rbenv

  • Pros: light and fast, not much to install.
  • Cons: may not work the first time.

The first thing to install is ruby_build. First you'll need Git on your system, if you don't have it already (you should) go get that first (get further info on that at ProGit). Then go to the website https://github.com/sstephenson/ruby-build. There you'll see the command line inputs to get ruby_build installed.


$ git clone git://github.com/sstephenson/ruby-build.git
$ cd ruby-build
$ ./install.sh

This should install ruby_build to usr/local, you may have to do sudo ./install.sh to get it to work.

That's the easy part. Now we need to get rbenv which will allow us to get multiple version of ruby installed but more importantly Ruby 1.9.3.

To install rbenv you need to create the directory where it will go, possibly adjust the path, check your ~/.bash_profile file for errors (I had some in there), then install Ruby 1.9.3 and possibly even delete some files and then re-install it (just to be on the safe side).

The instructions on how to install rbenv are on the website. They are also almost the same as the ones for ruby_build. First create a ~/.rbenv folder and then follow the commands on the website.

Immediately after you install rbenv check your .bash_profile file and make sure it looks ok. Mine was missing a line ending between two commands and would not work until I fixed that. Also be aware that because rbenv and ruby_build work using shims you need to re-build the look up paths or re-hash every time you install anything or do what I do: close the terminal and open a new terminal window.

Once you have rbenv installed you need to install Ruby 1.9.3 into it and ruby build uses this command shortcut to do it.
rbenv install 1.9.3-p0
After you install it some commands like Rails or Rake may still use the old path. I deleted these from the /usr/bin/ file and re-installed and that fixed it. But be aware that you need to re-start the terminal every-time you install. The rbenv rehash command didn't work once on mine as advertised, but restarting the terminal always did.

Recommended: JRuby

  • Pros: Easy install, works with Rails, plays well with other installations.
  • Cons: Requires the preface "jruby -S" on many commands, defaults to 1.8.7, doesn't have 1.9.3 yet.

To install Jruby just download the dmg installer from JRuby.org and follow the install instructions. To access Jruby just type jruby and the file name or jruby -S and the command. Additionally there a two shortcuts to the gem and irb commands in jgem and jirb. Also try out jirb_swing which is an irb session in a swing windows and has auto-complete.

To set JRuby to default to 1.9.2 you have to edit your .bash_profile file, more info on this blog post.
To use Rails with JRuby you may have to use the Java version of many gems, more info on this blog post.

JRuby is a good back up ruby and works fairly well overall. Don't be worried if the start-up seems to take forever, it's because it's loading all of Java first. Once Java is loaded it runs pretty well.

Comments

Popular posts from this blog

Building my own home.

I've decided. I want to build my own home. There is something special about building your own things. I built a desk for my tiny room when I first moved to L.A. My room was so small that I had to sit on the bed to use the computer so I build a high desk so I could sit on the bed and work on the computer. My roommate Trentity helped me cut the ply-wood to the right side. I still have that desk. It now sits on the living room covered by a cloth hiding the surplus of costume parts my current roommate Sean uses in his creations. Learning to build and fix things continue. And the feeling of satisfaction from fixing even small things is great. So a few years ago I heard on the NPR program the Story about a couple of educators that moved to a tent in their back-yard so they could rent their house and afford to send their kids to college. They had a special type of tent called a yurt and cooked and showered in an RV they had parked next to it. I thought I could do that. Housing in Lo

Contrasting Styles of Writing: English vs. Spanish

There is interestingly enough a big difference between what's considered good writing in Spanish and English . V.S. Naipul winner of the 2001 Nobel prize for literature publish an article on writing . In it he emphasizes the use of short clear sentences and encourages the lack of adjectives and adverbs. Essentially he pushes the writer to abandon florid language and master spartan communication . This is a desired feature of English prose , where short clipped sentences are the norm and seamlessly flow into a paragraph. In English prose the paragraph is the unit the writer cares about the most. This is not the case in Spanish where whole short stories (I'm thinking this was Gabriel Garcia Marquez but maybe it was Cortázar) are written in one sentence. Something so difficult to do in English that the expert translator could best manage to encapsulate the tale in two sentences. The florid language is what is considered good writing in Spanish but unfortunately this has lead t

My Fake Resume

Inspired by the over aggrandized bio of Joseph Rakofsky I want to write my own. If you don't know who he is; Joseph Rakofsky is a lawyer who earned a mistrial for a criminal client due to his (alleged) incompetence as reported on the Washington Post . There has been quite a few commentaries on his "Streisand-house" approach of suing all the bloggers and even the Washington Post and American Bar Association for reporting his (alleged) ineptitude. ("Streisand-house" is what happened to Barbara Streisand who wanted to have a picture of her mansion removed from the internet and she sued to have it removed. Unfortunately suing requires the filing of public documents with a picture of her house. The lawsuit had the direct opposite effect it intended. Everybody now could see legally, since it was a public document, a picture of her house.) But all that internet gossip aside I'm most impressed by his resume. Here is a quote from the website: Prior to stud