How to install REE or MRI 1.9.3 via RVM on OSX 10.7

Okay, if you happen to get errors when compiling REE or Ruby 1.9.3 on OSX 10.7, there is a high chance that you are using XCode 4.2 or 4.2.1.

gcc -g -O2  -pipe -fno-common    -DRUBY_EXPORT  -L.    main.o dmydln.o libruby-static.a -L/opt/local/lib -Wl,-rpath,/Users/mojo/.rvm/rubies/ree-1.8.7-2011.03/lib -L/Users/mojo/.rvm/rubies/ree-1.8.7-2011.03/lib -lsystem_allocator -ldl -lobjc   -o miniruby
ld: warning: directory not found for option '-L/opt/local/lib'
./ext/purelib.rb:2: [BUG] Segmentation fault
ruby 1.8.7 (2011-02-18 patchlevel 334) [i686-darwin11.1.0], MBARI 0x6770, Ruby Enterprise Edition 2011.03

make: *** [.rbconfig.time] Abort trap: 6

The solution is to set your CC back to the old gcc-4.2 aka non-llvm-gcc-4.2

$ export CC=/usr/bin/gcc-4.2

and force re-install REE:

$ rvm install ree --force

What’s wrong here? Xcode 4.2 on OSX Lion 10.7 default CC to llvm-gcc-4.2 which causes error in compiling REE under RVM. Worse, Xcode 4.2.1 completely removed gcc-4.2.

So what are workarounds out there?

1. Using osx-gcc-installer, please see this post

2. Compile GCC component for Xcode 4.2.x. I found an article on Caius Theory site which can be found here. Basically, what Caius did is to compile 4.1 developer tools to get gcc-4.2:

# Copied from
# Grab and unpack the tarball
$ mkdir ~/tmp && cd ~/tmp
$ curl -O
$ tar zxf gcc-5666.3.tar.gz
$ cd gcc-5666.3

# Setup some stuff it requires
$ mkdir -p build/obj build/dst build/sym
# And then build it. You should go make a cup of tea or five whilst this runs.
$ gnumake install RC_OS=macos RC_ARCHS='i386 x86_64' TARGETS='i386 x86_64' \
  SRCROOT=`pwd` OBJROOT=`pwd`/build/obj DSTROOT=`pwd`/build/dst SYMROOT=`pwd`/build/sym

# And finally install it
$ sudo ditto build/dst /

About Jones Lee

Nothing much about me..

10 responses to “How to install REE or MRI 1.9.3 via RVM on OSX 10.7

  1. This trick also works on 10.6.8. Thanks!

  2. Thanks for the tip. This got me out of a bind.

  3. gcc-4.2 is no longer installed by xcode 4.2 on lion.

    Where can I get gcc-4.2?

  4. This was exactly what I was looking for, although setting $CC had no effect for me.

  5. You just saved me hours of frustration- thank you!

  6. If you don’t have gcc-4.2 you might want to become a Apple developer and download xCode 3 from dev center

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: