Twitter Updates

Monday 14 December 2009

Problems with Snow Leopard and Ruby Gems

UPDATE 2 (update 1 at the bottom with some extra ruby version info)
When you install Xcode make sure is is the latest version. I must have at some point installed the old Leopard version. then when things did not work reinstalled that same old version. I found xcode321_10m2003 in my downloads folder not the older one I had put in a software folder. You may still need to update Ruby to a new version.

Make sure you have the latest Xcode.


I have been trying to get the very simple Sinatra (a light ruby on Rails) setup working following the verysimple instructions on http://www.sinatrarb.com/

Make a file called hi.rb with this inside:
require 'rubygems'
require 'sinatra'
get '/hi' do
"Hello World!"
end

Then run these commands:
$ gems install sinatra
$ ruby hi.rb


They fail with:
hi.rb:2:in `require': no such file to load -- rubygems (LoadError)
from hi.rb:2

After removing the require 'rubygems', is it actually still required ?
hi.rb:3:in `require': no such file to load -- sinatra (LoadError)
from hi.rb:3

To fix this I ran through the instructions at http://hivelogic.com/articles/compiling-ruby-rubygems-and-rails-on-snow-leopard/

Their instructions worked well until the mysql gem which I do not require at the moment but do like to get my set up the same as the tutorial. I found the following line on stackoverflow.
$ sudo env ARCHFLAGS="-arch x86_64" gem install mysqlplus


Finally got the basic sinatra working by calling:
$ /usr/local/bin/ruby hi.rb
Even though which ruby returns /usr/local/bin/ruby, so why does ruby hi.rb not just work!

What is going on just thought I would check to see if calling the other ruby breaks it, but it works fine.
$ /usr/bin/ruby hi.rb


UPDATE
For completeness and to answer Spyro7's Question:
$ /usr/local/bin/ruby -v
> ruby 1.8.7 (2009-06-12 patchlevel 174) [i686-darwin10.2.0]

$ /usr/bin/ruby -v
> ruby 1.8.7 (2008-08-11 patchlevel 72) [universal-darwin10.0]

5 comments:

Spyro7 said...

I may be completely wrong about this, but it looks like you are using the ruby version included with mac os. Have you ever considered just using the macports.org ruby?

To the best of my knowledge, that version is a little more up to date and should be working with 10.6 fine by now. I haven't made the jump to snow leopard yet myself, but I think that it is strange that this could be happening. What is the output of ruby -version?

Spyro7 said...

Sorry for the double comment, but maybe this is a known phenomena?

http://identi.ca/notice/15894074

A Person said...

Thanks Spyro7, actually once rebooted I could just call ruby hi.rb instead of an absolute path.

I have been using macports but that has never worked correctly for me since moving to Snow leopard. I did an upgrade rather than a clean install of OS X.

If you are going to move to snow leopard do a clean install.

You must also reboot after installing Xcode. it causes random commands to fail on the command line until you do. I keep seeing errors associated with Xcode not being installed but I have done that 3 times now.

I have got the basic sinatra working but I now can not get sqlite3 to install via ports. I blame all this 64 bit stuff, I am sure it will come right in a few months as all the problems are resolved.

A Person said...

Looks like every one who said Xcode was the answer was right! I had just been installing the older version by accident.

From now on I will probably seperate my software folder up version of OS X so I do not accidentally install Leopard only software on Snow Leopard.

Spyro7 said...

Morgy,

Thanks for the tips. I was wondering if a clean install would be best. Now you've resolved that question for me.

Also, you're right - the 64-bit stuff is causing a lot of problems in ports-land for quite a few people.

I will probably hold off on snow leopard for atleast another update package or so...