Mark Needham

Thoughts on Software Development

Installing Ruby 1.9.2 with RVM on Snow Leopard

with 65 comments

Yesterday evening I decided to try and upgrade the Ruby installation on my Mac from 1.8.7 to 1.9.2 and went on the yak shaving mission which is doing just that.

RVM seems to be the way to install Ruby these days so I started off by installing that with the following command from the terminal:

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

That bit worked fine for me but there are further instructions on the RVM website if that doesn’t work.

My colleague David Santoro pointed me to a post on ASCIIcasts detailing the various steps to follow to get Ruby installed.

Unfortunately my first attempt…

rvm install 1.9.2

…resulted in the following error in the log file:

yaml.h is missing. Please install libyaml.
readline.c: In function ‘username_completion_proc_call’:
readline.c:1292: error: ‘username_completion_function’ undeclared (first use in this function)
readline.c:1292: error: (Each undeclared identifier is reported only once
readline.c:1292: error: for each function it appears in.)
make[1]: *** [readline.o] Error 1
make: *** [mkmain.sh] Error 1

I thought that perhaps ‘libyaml’ was the problem but Michael Guterl pointed me to a post on the RVM mailing list which suggests this was a red herring and that the real problem was ‘readline’.

That led me back to a post on the RVM website which explains how to install ‘readline’ and then tell RVM to use that version of readline when installing Ruby.

I tried that and then ran the following command as suggested on Mark Turner’s blog post:

rvm install 1.9.2-head -C --enable-shared,--with-readline-dir=/opt/local,--build=x86_64-apple-darwin10

That resulted in this error:

ld: in /usr/local/lib/libxml2.2.dylib, file was built for i386 which is not the architecture being linked (x86_64)
collect2: ld returned 1 exit status
make[1]: *** [../../.ext/x86_64-darwin10/tcltklib.bundle] Error 1
make: *** [mkmain.sh] Error 1

Michael pointed out that I needed to recompile ‘libxml2.2′ to run on a 64 bit O/S as I’m running Snow Leopard.

I hadn’t previously used the ‘file’ function which allows you to see which architecture a file has been compiled for.

e.g.

file /usr/local/lib/libxml2.2.dylib
 
/usr/local/lib/libxml2.2.dylib: Mach-O dynamically linked shared library i386

I had to recompile ‘libxml2.2′ to run on a 64 bit O/S which I did by downloading the distribution from the xmlsoft website and then running the following commands:

tar xzvf libxml2-2.7.3.tar.gz 
cd libxml2-2.7.3
./configure --with-python=/System/Library/Frameworks/Python.framework/Versions/2.3/
make
sudo make install

Re-running RVM Ruby installation command I then had this error instead:

tcltklib.c:9539: warning: implicit conversion shortens 64-bit value into a 32-bit value
ld: in /usr/local/lib/libsqlite3.dylib, file was built for i386 which is not the architecture being linked (x86_64)
collect2: ld returned 1 exit status
make[1]: *** [../../.ext/x86_64-darwin10/tcltklib.bundle] Error 1
make: *** [mkmain.sh] Error 1

I downloaded the sqlite3 distribution and having untarred the file ran the following commands as detailed on this post:

CFLAGS='-arch i686 -arch x86_64' LDFLAGS='-arch i686 -arch x86_64' 
./configure --disable-dependency-tracking
make
sudo make install

Next I needed to recompiled ‘libxslt’ which I downloaded from the xmlsoft website as well before untarring it and running the following:

./configure
make
sudo make install

Having done that I re-ran the RVM Ruby installation command:

rvm install 1.9.2-head -C --enable-shared,--with-readline-dir=/opt/local,--build=x86_64-apple-darwin10

And it finally worked!

The magnificent yak is borrowed under the Creative Commons Licence from LiminalMike’s Flickr Stream.

Be Sociable, Share!

Written by Mark Needham

July 8th, 2010 at 1:10 pm

Posted in Ruby

Tagged with

  • Rick

    Thanks, this got me up and running!

  • Emerson Lackey

    This post is the best post in the world. I tried for days until I hit this post. Thank you, thank you, thank you.

  • http://twitter.com/FeatureMonkey Michael Belanger

    Wow – thanks!!! this worked for me as well. Nothing else did.  One addition is I had to use the same method for 1.8.7 first as 1.9.2 used ruby scripts in the install process.  thanks again!

  • Schaerli

    wow thanks great work :D

  • Anonymous

    Thank you:) After downgrading to Xcode 4.1, I tried your solution and it worked without a hitch!
    Will going back to Xcode 4.2.1 (Mac 10.7.2) cause problems?
    Many gracious thanks

  • Rods

    Thanks a lot!!
    getting rvm going was easy enough for a novice like me, but this was extremely useful to figure out my various errors when actually installing any rails version.

  • http://twitter.com/1Copenut Trevor Pierce

    Downgrading to Xcode 4.1 (on Lion 10.7.2) and running through this post enabled me to do a simple rvm install 1.9.2 and it worked flawlessly. Learned a great deal about dynamic libraries and their build architecture along the way. Thank you very much!

  • Stu

    1.5 years later and this post is still saving lives. Thanks a million!

  • Beep

    I tried entering what was stated in the article:
    bash < <( curl http://rvm.beginrescueend.com/releases/rvm-install-head )
    which gave me an error message saying the 301 had changed, so i found this instead 
     bash -s stable < <(curl -s https://raw.github.com/wayneeseguin/rvm/master/binscripts/rvm-installer)

    which i ran on the command line and lo and behold it downloaded the rmv. 

  • Nanichandu84

    Thanks so much it solved my problem…..

  • Marou

    Thank you so much, after several tries of many hours, i finally got around installing Rails thanks to your blog. Cheers !

  • Anonymous

    It worked! Man, do you have ANY idea how hard I tried to make all this work? Then your magical simple post did the job. Finally found someone with my same issue. Thank you for sharing this!

  • Anonymous

    This SAVED me after two full days of sadness. Thank you so much. God bless you.

  • Mcnute

    Thank you soooooo much from Germany! Everything worked fine with your detailed description. Such a good step by step explanation. Thank you again!!

  • Pingback: Installing Ruby 1.9.2 with RVM on Snow Leopard at Mark Needham | Bob Chesley