small medium large xlarge

18 Jun 2008, 16:22
Stephyn G W Butcher (2 posts)

I typed the following code from the book:

require 'osx/cocoa'

include OSX

class AppDelegate < NSObject
	def applicationDidFinishLaunching( aNotification)
		puts "#{} makes me say: Hello, world!"
		puts "#{aNotification.object} is the object notifying"
NSApp.setDelegate( AppDelegate.alloc.init)

and received the following error when I ran it:

$ ruby basic.rb 
2008-06-18 12:01:36.728 ruby[5702:10b] WARNING: multiple libruby.dylib found: '/usr/local/lib/libruby.dylib' and '/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/libruby.1.dylib'
2008-06-18 12:01:36.730 ruby[5702:10b] RBCocoaInstallRubyThreadSchedulerHooks: warning: rb_set_cocoa_thread_hooks is linked from a different library (/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/libruby.1.dylib) than ruby_init (/usr/local/lib/libruby.dylib)
Segmentation fault

This occurs basically because I have two different Ruby installations.

$ which ruby

and the one that is pointed to by /usr/bin/ruby in /System/Library/Frameworks/Ruby.framework/Versions/Current/usr/bin/.

I’m still trying to work out what the “right” thing to do is. I use the /usr/local/bin/ruby version for work.

For now, I’m just prepending:


to my scripts, making them executable with chmod 755 and viola:

$ ./basic.rb 
NSApplicationWillFinishLaunchingNotification says that the application will finish launching.
NSApplicationDidFinishLaunchingNotification makes me say: Hello, world!
<NSApplication: 0x510dd0> is the object notifying

everything works as expected.

It isn’t an ideal solution but works and might help someone who runs into the same problem.

Cheers, Steve

19 Jun 2008, 16:58
Brian Marick (56 posts)

Most of the Ruby in the book is run as part of a OSX app, not an independent script, so your solution probably suffices. I believe a regular app will pick up the right Ruby. If not, mail me at

It’s possible you might also have problems with multiple RubyCocoa installations. Here’s some text from the upcoming beta2 that might help:

  I also have many of the examples log RubyCocoa's
  version to the console (visible via the Console
  app). If you manually installed a version of
  RubyCocoa before you installed Leopard, that old
  version may be loaded in preference to Leopard's
  (by an application, but not
  by <commandname>irb</commandname>). See
  <pref linkend="id.gotchas"/> if samples behave
  oddly, you check the console, and the version is old.

If your application logs version to the console and the version is older than that gotten from IRB, probably installed version before leopard. If there’s a version in /Library/Frameworks/RubyCocoal.framework, delete it.

19 Jun 2008, 16:59
Brian Marick (56 posts)

Whoops - didn’t copy the important bit, which comes before the last para above:

  To see what version of RubyCocoa you're running,
  type this to <commandname>irb</commandname>:

<code language="irb"> irb(main):001:0> require 'osx/cocoa' => false irb(main):002:0> OSX::RUBYCOCOA_VERSION => "0.13.1"
01 Feb 2009, 16:45
Tommy Sundström (11 posts)

How can I control what RubyCocoa-version Xcode will be using?

Currently, when i do OSX::RUBYCOCOA_VERSION in irb I get “0.13.1”, while when I do it in an application that I do it from Xcode I get “0.12.0”.

Both in irb and Xcode I can do require ‘osx/cocoa’. Gems installed from irb is however not accessible from Xcode.

(As far as I know I have not installed different versions of RubyCocoa, but I have installed and experimented with MacRuby.)

02 Feb 2009, 00:57
Tommy Sundström (11 posts)

By dragging “RubyCocoa.framework” folder out /Library/Frameworks and restarting, I got Xcode to change version. Now when I do


I get “0.13.1”.

However, I still suspect that it is two different instances, since a gem that is available via irb, is not available via Xcode.

02 Feb 2009, 22:28
Brian Marick (56 posts)

Your app’s environment is set up so that it doesn’t include anything outside the app bundle other than what Apple delivers. If you want to use a gem in your app, you should put it inside your app’s source directory. See chapter 9.

Alternately, if you want to mess with paths, see the file “path-setting.rb” inside the Fenestra source.