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

  • Melanio Reyes

    Wow, you too? I had to go through a similar process of trial and error when trying to install rvm on linux ubuntu. You’re lucky you had some help. I needed rvm because I needed different ruby and rails versions for the various apps I was supporting.

  • Haha too right! I’m a complete novice with this type of thing so I’d have been completely lost without the help

  • Raf

    Thanks for this! Finally got RVM working and fixed my Nokogiri woes as well. 🙂 Why oh why aren’t libxml, libxslt, and sqlite compiled for 64bit by default?

  • Will any of this stuff kill my system’s Ruby 1.8.7. Won’t another program need the 32bit version of any of these libraries?

  • I actually have 1.8.7 installed as well and I found that to do that I needed to have those binaries compiled at 64 bit as well so I think you’ll always need 64 bit if you’re running on Snow Leopard.

    Could easily be wrong with that last assumption though…

  • Hey,

    I’m pretty f****ng clueless, so please strike this comment if it’s dumb – but I found the readline path installed like this:

    info: Installing readline to /Users/markc/.rvm/usr

    I had to amend the rvm command as follows

    rvm install 1.9.2-head -C –enable-shared,–with-readline-dir=/Users/markc/.rvm/usr,–build=x86_64-apple-darwin10

    ie changed the with-readline-dir to match what rvm did with readline.

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

    Worked great with me. Thanks.
    Now you don’t need to add “-head”. I am told that is automatic.

    Does anyone know if i can share gems across ruby versions ? (I don’t wish to install the same gems for ree, 1.9.1, 1.9.2 etc).

  • Mikey J

    Thank you so much Mark.

    I’ve been trying to get RVM to install ruby 1.9.2 for days, and kept running around in circles looking for libyaml, but after following your guide, I was finally able to get RVM running.

  • Simon

    Apparently these problems are due to license restrictions in readline, more here: http://www.toshikikuchi.com/2010/06/ruby-now-rejects-to-link-readline-6.html I hate licenses…

  • Trying to run the last command I got this error:

    “To proceed rvm requires a 1.8-compatible ruby is installed. We attempted to install 1.8.7 automatically but it failed.”

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

    The above command, infact, requires a previous installed Ruby version. If you haven’t one, run this instead:

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

  • ian

    man.
    i just reshaved the yak!

  • Genius. Thanks!

  • Pingback: Snow Leopard upgrade pain… « Cowboy Coded()

  • Awesome post! Readline & RVM were giving me a serious headache after snow leopard upgrade. I appreciate you posting this.. it definitely saved me some time.

  • GF

    This helped a lot. My Snow Leopard didn’t have libyaml installed either, so I had to download the latest from http://pyyaml.org/wiki/LibYAML and install that as a step before rvm’s install of Ruby was really done. Prior to running through all the steps above I couldn’t get the newly added ‘Psych’ to load in irb. After loading libyaml (and doing everything above) I was able to get it to “require”.

  • GF

    Well, my above comment was referring to my home Mac, which had been on Leopard, then recently upgraded to Snow Leopard. It knows about the new Yaml “Psych”, but my new Mac Pro desktop system here at work, which has always been Snow Leopard, still doesn’t recognize psych when I’m in irb and do a ‘require “psych”‘. I’ve stepped through it all a couple times and no joy so I’m bailing on it. YAML is still functional and hopefully something will show up that clears up the problem.

  • susatadahiro

    thanks.
    this article saved me.

  • Mariano

    dude.. i want to thank you because i spent so many hours trying to get this thing work and i did it because i fell here.. so.. many thanks for all this

  • Angel

    THANK YOU!!! I am new to Mac and have been struggling with this install for a couple weeks now. Dude, thanks!!!!!

  • Jakob Squamigera

    Oh man, after days trying I was close to giving up this… until I found this post here! Thank you SO MUCH!!!

  • yixi-zhang

    Just another note. If you claim CFLAG & CXXFLAG arch=i386 then even –build=x86_64-apple-darwin10 won’t override the compiling environment. So fix your .profile or .bashrc.

  • Hey there, I just wanted to drop a note thanking you for documenting your struggles. You saved me untold hours of frustration. So… Thanks!

  • Life saver. Very good capture of what could go wrong when installing Ruby 1.9.2 on OSx

  • JIm

    Awesome post which fixed the problems I was having. Thanks.

  • Arturs

    THANK YOU. I’m 12 and I spent all day searching for ways to install ruby 1.9.x so I could use bowline to make apps. This finally worked.

  • Grace

    Hi, I followed this blog, but it appears that even with -–build=x86_64-apple-darwin10, rvm is still configuring ruby 1.9.2 for target i386 … I looked at my configure.log file and make.log file generated. They seem to refer to 1.9.1 and i386.
    Does anyone know why this is and how I can go about fixing this?
    Note that all my other libraries are x86_64 (that is libxml2, readline)

    Thanks!

  • Pingback: links for 2010-12-10 « Breyten’s Dev Blog()

  • Adrian

    Thanks great post, really useful, but just incase anyone has the problems I did you may also want to reinstall libxslt as that was coursing an issue for me too. You can get it from xmlsoft website too

  • Thanks, Mark. I just upgraded to SL today, and this helped a lot. I’ve now got 1.9.2 running and C extensions compiling.

  • Mark88

    For those happening upon this blog post after several months since it’s posting date, try this first:

    http://bit.ly/eeTF72

    Very simple and it worked without a hitch for me. Allows you to keep your original install and use “rvm use 1.9.2” to switch to newly installed version.

  • hunter

    A great post to get my instance working. Thanks!

  • Pingback: links for 2011-01-28 « Bloggitation()

  • glenn

    thanks so much for this! the sqlite3 issue was driving me nuts…

  • ashok

    thanks a ton man… it helped solve the issue 🙂

  • jpfinlay

    Thanks for the post – I’d have been lost without it! Can’t understand how I had this problem with my relatively new iMac, but not with my old macbook running Snow Leopard…

  • Andrew

    Just in case this happened to anyone else…

    I followed all the steps above, but ran into yet another error related to libiconv:

    ld: in /usr/local/lib/libiconv.2.dylib, file is not of required architecture
    collect2: ld returned 1 exit status
    make[1]: *** [../../.ext/x86_64-darwin10/tcltklib.bundle] Error 1
    make: *** [mkmain.sh] Error 1

    As with libxml and libxslt (etc), downloading and rebuilding libiconv via http://gnu.spinellicreations.com/gnu/libiconv/, and then doing a basic:

    ./configure
    make
    sudo make install

    …led to a successful compile of ruby 1.9.2-p180 in conjunction with the other fixes above.

  • Frank

    Thanks!

  • Chris

    I’m not even getting to the point where I can USE rvm to update ruby gems on OS X.

    I get the errors:

    -bash: rvm_error: command not found
    cat: /Users/adminrv/.rvm/VERSION: No such file or directory
    -bash: __rvm_conditionally_add_bin_path: command not found

    This is after adding the following to my .bash_profile:

    [[ -s “$HOME/.rvm/src/rvm/scripts/rvm” ]] && . “$HOME/.rvm/src/rvm/scripts/rvm”

    The instructions on various sites actually indicate to the following paths but I believe them to be wrong (didn’t work either):

    [[ -s “$HOME/.rvm/scripts/rvm” ]] && . “$HOME/.rvm/scripts/rvm”

    Does anyone have any ideas? Thanks if so.

    I’ve spent about 3 hours just trying to get git, rvm, ruby gems and then ruby installed to their latest versions on OS X 10.6 little success (stuck per above). I hope the installation process is not an indication of the viability of ruby on rails itself. What a PITA.

  • Joe

    Thanks so much for this. I lost about eight hours before I found this page on rails and rvm issues. Might want to add ‘rvm –default use 1.9.2’ at the bottom for completeness. Awesome job!

  • Donovan

    Thank you!  This saved me *hours*!  What a hassle.

    I ended up needing to install a few other things as well, like libtools and readline.  I also had to reinstall libxml and libxslt a second time into /usr/local before ruby 1.9.2 would compile correctly.

  • Lyhu

    Thank you for sharing, I successfully install Ruby-1.9.2 version follow steps of this article shows.

  • Thanks for this. I had exactly the same problem and have now got Ruby 1.9.2 successfully installed via RVM

  • Nohuber

    thanx a lot. i went though exactly the same process – i was about to give up before i found your walk-through 🙂

  • Justin+comments

    This post was extremely helpful. Thanks Mark!

  • ZZ

    Thanks! This worked for Lion too! 

  • Pingback: Installing Ruby 1.9.2 with RVM on Snow Leopard at Mark Needham « CFMeta()

  • Wow. Thanks quite a work.. luckily i didnt get so many errors.. Will post it as reference in my link.. 

  • Anonymous

    I’ve been trying to get 1.9.2 on my Mac for years it seems. Every few months a tutorial grabs my attention and in I go, only to have my hopes dashed once again. This time it was another friendly sounding How To from NetTuts. Ha! I gave up last night but revisited and found your post. I had to follow each of the steps you outline. Thank You it’s working!
    PS, I found a little help with readline errors here: https://rvm.beginrescueend.com/packages/readline/

  • Michael Jackson

    Holy cow, thank you so much.  I didn’t have the libyaml problem, but besides that, I followed your instructions to a T.  A+++++ post, would read again.

  • thanks a ton!! I was going crazy with the installations until I checked your post!

  • 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.

  • 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 😀

  • 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.

  • 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()