installing ruby 1.8.6 on OSX

UPDATED Removing native OSX’ ruby is a bad idea. Just use rvm or similar tool instead.

Restoring OSX ruby is pretty easy though: just copy your /System/Library/Ruby and /System/Library/Frameworks/Ruby.framework dirs from another OSX installation.

Setup Script

setup-osx-ruby-1.8.6.sh (download)

Notes, Ruby on Osx

Ruby 1.8.7 is a default version(at the moment) OS X ships with.

root# ls -l /usr/bin/|grep 'Frameworks\/Ruby'
erb -> ../../System/Library/Frameworks/Ruby.framework/Versions/Current/usr/bin/erb
gem -> ../../System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/bin/gem
irb -> ../../System/Library/Frameworks/Ruby.framework/Versions/Current/usr/bin/irb
rdoc -> ../../System/Library/Frameworks/Ruby.framework/Versions/Current/usr/bin/rdoc
ri -> ../../System/Library/Frameworks/Ruby.framework/Versions/Current/usr/bin/ri
ruby -> ../../System/Library/Frameworks/Ruby.framework/Versions/Current/usr/bin/ruby
testrb -> ../../System/Library/Frameworks/Ruby.framework/Versions/Current/usr/bin/testrb

To avoid possible conflicts I just uninstalled Ruby 1.8.7 by removing it along with symlinks.

# removing symlinks
sudo rm -f /usr/bin/{erb,gem,irb,rdoc,ri,ruby,testrb}

#Then remove installed wrappers:
grep -R '#!/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/bin/ruby' /usr/bin/|cut -d: -f1 |sudo xargs rm -f
  
#removing Ruby.framework
root# rm -rf /System/Library/Frameworks/Ruby.framework/

# once ruby186 port installed
# verify environment
gem env path
["~/.gem/ruby/1.8", "/opt/local/lib/ruby/gems/1.8"]

Notes, Rmagick

At the moment of writing, 6.6.1 is the latest ImageMagick’s version But when the rmagick-1.15.14 gem is built against it - gem fails with error:

dyld: NSLinkModule() error
dyld: Symbol not found: _DestroyConstitute
  Referenced from: /Users/marjanhratson/.gem/ruby/1.8/gems/rmagick-1.15.14/lib/RMagick.bundle
  Expected in: flat namespace
  in /Users/marjanhratson/.gem/ruby/1.8/gems/rmagick-1.15.14/lib/RMagick.bundle
Trace/BPT trap

To overcome this issue we need to fallback to older ImageMagic-6.5.6 version: read on

Notes, ruby

Besides above rmagick error, ruby wasn’t operable as stuck all the time. _GDB_ing showed issue:

(gdb) bt
#0  0x00007fff850eb7a2 in semaphore_wait_signal_trap ()
#1  0x00007fff850f0ced in pthread_mutex_lock ()

Google kindly suggested conversation with simlar issue. And dln.c patch worked for me as well.

Comments