Installing Ruby 1.9.2 with RVM on Snow Leopard
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.
About the author
I'm currently working on short form content at ClickHouse. I publish short 5 minute videos showing how to solve data problems on YouTube @LearnDataWithMark. I previously worked on graph analytics at Neo4j, where I also co-authored the O'Reilly Graph Algorithms Book with Amy Hodler.