How to fix that Rubygems mess on Leopard

Ruby on Rails, Software development Add comments

I love Leopard and I love my Mac. I think Apple made the right decision by bundling Ruby and Rails with Leopard. However, I believe they screwed up big time in the execution.

Leopard’s Rails installation worked great until I updated Rubygems with sudo gem update –system. After I did that, most of my gems were broken, and reinstalling them didn’t help. According to Google, I was not alone.

The right thing to do for Apple would have been to ship Leopard with MacPorts and have Ruby and Rubygems installed through it. Unfortunately, they had to reinvent the wheel…

This tutorial will guide you through fixing that mess. We will be reinstalling Ruby and Rails with MacPorts and deleting the original Ruby installation to avoid conflicts.

You might want to backup your system before proceeding as I cannot be held responsible if something goes wrong (my lawyer made me write that). I tried it on 2 different machines and it worked fine for me.

So let’s get started already!

Step 1: Install MacPorts

Start by installing MacPorts if you don’t already have it on your machine. It’s an awesome must-have piece of software anyways! It’s super easy to install with the Leopard package.

Step 2: Install XCode 3.0

You must also have XCode 3.0 installed. It’s a huge download so you might want to install it from your Leopard DVD. It’s in /Optional Installs/Xcode Tools/XcodeTools.mpkg

Installation will take some time, so go read Digg, Reddit, or install Defensio on your blog!

Step 3: List your gems

Get a list of your installed gems and save it to a text file somewhere. You will need to reinstall them!

Step 4: Clean up your Mac

In order to avoid conflicts with your original Ruby installation, I recommend you simply delete it. To do so, run these commands (I know… scary stuff!):

Step 5: Install Ruby and Rubygems with MacPorts

If you don’t perform step 4, you will run into problems at step 6.

Now go ahead and install Rubygems through MacPorts. It will automatically install Ruby (and many other things) as it’s a dependency. The command is:

This one will also take a while… When it’s done, update Rubygems:

Step 6: Install Rails

At this point, you should have a brand new Ruby and Rubygems installation working! That wasn’t too hard was it?

Now let’s install Rails.

  • For Rails 1.2.6, run
  • For Rails 2 (aka latest-and-greatest), run

Note that recent versions of Rubygems no longer requires the –include-dependencies parameter.

Step 7: Reinstall your gems

Now’s the time to reinstall your original gems.

To reinstall the gems that shipped with Leopard, execute this command:

Then, you might want to reinstall the other gems you had. The list is on your desktop in installed_gems.txt.

That’s it! You now have a more standard and less prone to problems Rails stack on your Mac!

27 Responses to “How to fix that Rubygems mess on Leopard”

  1. Kevin Says:

    Next step: fire up Instruments and begin analyzing your Ruby app with dtrace … oops. (kidding)

    I didn’t have any trouble upgrading rubygems to 0.9.5, and am still using the pre-installed Ruby. What will I do when Ruby 2.0 comes out? I don’t know yet. I can always switch to the MacPorts build of Ruby, but I like knowing I have the power of DTrace at my disposal if I need it.

  2. Mathieu Martin Says:

    Hey Carl, my lawyer will be contacting yours! Kidding ;-) Thanks for the heads up.

  3. Jason Says:

    I’m just speculating, but I would imagine all those things you deleted might show back up in a future Software Update. Also, by removing Ruby.framework you are probably going to break any RubyCocoa apps (not that there are many, yet).

    MacPorts installs software into /opt (or is it /sw, always confuse it and Fink), so you should be able to install Ruby from there and use it simply by ensuring your PATH is setup correctly.

    Installing MacPorts Ruby should be fine, but removing the system installed version is just asking for trouble.

  4. Carl Mercier Says:

    Jason,

    I had problems with Rubygems when I didn’t delete the original installations, that’s why I chose the more drastic way. So far, so good. Everything works fine. I haven’t tried any RubyCocoa apps, though.

  5. Daniel Wintschel Says:

    I could be wrong, but you shouldn’t need to delete the Apple bundled Ruby install if you simply install Ruby via MacPorts, and then add /opt/local/bin at the beginning of your $PATH (just do that in ~/.bash_login).

  6. Carl Mercier Says:

    Daniel,

    I thought the same, but I had problems with Rubygems when I didn’t remove it. It was complaining about the sources gem not being found… maybe there’s a better workaround? I’d rather keep the default installations there too.

  7. James Says:

    This was a life saver something happened when I upgraded to rails 2.0 and none of my rails apps would run on my mac pro. They would run fine on my laptop which I didn’t upgrade but something happened on the desktop. This saved me I don’t mind developing on the laptop when Im not home, but to have to do it in the comfort of my own office was torture!

  8. links for 2007-12-16 « Accidental Technologist Says:

    [...] Carl Mercier’s blog » Blog Archive » How to fix that Rubygems mess on Leopard Need help with fixing gems on Leopard? (tags: mac Ruby leopard) [...]

  9. dy Says:

    when I update gems display this:
    /opt/local/lib/ruby/vendor_ruby/1.8/rubygems/custom_require.rb:27:in `gem_original_require’: no such file to load — sources (LoadError)
    from /opt/local/lib/ruby/vendor_ruby/1.8/rubygems/custom_require.rb:27:in `require’
    from /opt/local/lib/ruby/vendor_ruby/1.8/rubygems/source_info_cache.rb:6
    from /opt/local/lib/ruby/vendor_ruby/1.8/rubygems/custom_require.rb:27:in `gem_original_require’
    from /opt/local/lib/ruby/vendor_ruby/1.8/rubygems/custom_require.rb:27:in `require’
    from /opt/local/lib/ruby/vendor_ruby/1.8/rubygems/remote_installer.rb:12
    from /opt/local/lib/ruby/vendor_ruby/1.8/rubygems/custom_require.rb:27:in `gem_original_require’
    from /opt/local/lib/ruby/vendor_ruby/1.8/rubygems/custom_require.rb:27:in `require’
    from /opt/local/lib/ruby/vendor_ruby/1.8/rubygems.rb:112:in `manage_gems’
    from /opt/local/bin/gem:10

  10. Carl Mercier Says:

    dy: did you delete the original Ruby as per my instructions? I had the same problem when I didn’t.

  11. dy Says:

    oops.
    I forgot it,thanks

  12. Gary Haran Says:

    I had a little problem with my ferret install at some point and this fixed everything for me! Thanks Carl!

  13. James O'Kelly Says:

    I removed my /library ruby and gems stuff as you specify and I still can’t run gem due to the gem_original_require path.

    My path is: /opt/local/bin:/opt/local/sbin:/usr/local/bin:/usr/local/sbin:/usr/local/mysql/bin:$PATH

  14. Carl Mercier Says:

    James,

    Try pasting the whole error message. It will help.

  15. Aris Says:

    I have the same problem with running gem due to the gem_original_require path


    /opt/local/lib/ruby/vendor_ruby/1.8/rubygems/custom_require.rb:27:in `gem_original_require': no such file to load -- sources (LoadError)
    from /opt/local/lib/ruby/vendor_ruby/1.8/rubygems/custom_require.rb:27:in `require'
    from /opt/local/lib/ruby/vendor_ruby/1.8/rubygems/source_info_cache.rb:6
    from /opt/local/lib/ruby/vendor_ruby/1.8/rubygems/custom_require.rb:27:in `gem_original_require'
    from /opt/local/lib/ruby/vendor_ruby/1.8/rubygems/custom_require.rb:27:in `require'
    from /opt/local/lib/ruby/vendor_ruby/1.8/rubygems/remote_installer.rb:12
    from /opt/local/lib/ruby/vendor_ruby/1.8/rubygems/custom_require.rb:27:in `gem_original_require'
    from /opt/local/lib/ruby/vendor_ruby/1.8/rubygems/custom_require.rb:27:in `require'
    from /opt/local/lib/ruby/vendor_ruby/1.8/rubygems.rb:112:in `manage_gems'
    from /opt/local/bin/gem:10

  16. Aris Says:

    Just found a fix for the gem_orginal_require problem.

    sudo port selfupdate
    sudo port uninstall rb-rubygems
    sudo port install rb-rubygems

    I found it at http://www.nabble.com/Ruby-Fails-td14098557.html

  17. Laurent Sansonetti Says:

    FYI, RubyGems supports Leopard since 0.9.5. You can safely do gem update –system and it will not break Leopard’s Ruby configuration.

    The same goes for RubyGems 1.0.

  18. macournoyer Says:

    Thx for the tips Carl,

    I did as you said but installed everything from source, ruby work all right but TextMate shebang was broken, I had to play w/ the path in .MacOSX/environment.plist

  19. Philippe Rathe Says:

    I was about to follow your instructions but tried to find another way. I’ve installed rubygems 1.0.1 from source. And I set some env variables to install gems in my home dir and change my $PATH.

    My gems are install in ~lib/rubygems.

    This is in my ~/.bash_profile

    #Where to read from
    export GEM_PATH=/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/gems/1.8:/Library/Ruby/Gems/1.8:~/lib/rubygems
    #Where to write
    export GEM_HOME=~/lib/rubygems
    export PATH=~/lib/rubygems/bin/:$PATH

    Don’t get any trouble yet.

    Thanks Carl!

  20. Philippe Rathe Says:

    @James,

    When something goes wrong with rubygems, the first thing to do is removing every source_cache file that it uses before going further. It will regenerate it at the next invocation of gem.

  21. Mike Says:

    From

    sudo port install rb-rubygems

    I get the message:

    Warning: Group file could not be located.
    Error: Unable to open port: invalid command name “ruby.setup”

    Any ideas hugely appreciated,

    Mike

  22. Andy Says:

    Hi Carl. I had no trouble during installation, but I can’t get the new Rails location to take effect. I think this is a basic $PATH problem. I tried editing my ~/.bashrc file (using bash) but I’m having no luck.

    andy$ rails -v
    -bash: /usr/bin/rails: /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/bin/ruby: bad interpreter: No such file or directory

    Any advice? thanks.

  23. Andy Says:

    OK I opened ~/.bash_profile and moved the /opt/local/bin $PATH entry in front of the /usr/bin entry which had the Leopard Rails install. Now when I do a ‘which rails’ it shows the Macports version. ‘Rails -v’ shows my macports version. So I should be good now. But I’m still wondering if there is a conventional way of specifying which version on a command by command basis, should be used when there are 2 or more versions installed on a system.

    Will OS X updates re-install the removed Rails stack?

  24. Danyel Lawson Says:

    For those of you looking to fix the underlying problem rather than burying it you should check out my post on how to get the Leopard version working again.
    http://freegnu.blogspot.com/2008/03/rails_requires_rubygems_094_error_on.html

  25. Danyel Lawson Says:

    Oops. Bad link.
    The correct one is:
    http://freegnu.blogspot.com/2008/03/rails-requires-rubygems-094-error-on.html
    It’s dashes not underscores.

  26. noah Says:

    I can’t seem to get past Step 5. After running deleting the default files as per Step 4, I am still getting this when I try $ sudo gem update –system :
    /opt/local/lib/ruby/vendor_ruby/1.8/rubygems/custom_require.rb:27:in `gem_original_require’: no such file to load — sources (LoadError)
    from /opt/local/lib/ruby/vendor_ruby/1.8/rubygems/custom_require.rb:27:in `require’
    from /opt/local/lib/ruby/vendor_ruby/1.8/rubygems/source_info_cache.rb:6
    from /opt/local/lib/ruby/vendor_ruby/1.8/rubygems/custom_require.rb:27:in `gem_original_require’
    from /opt/local/lib/ruby/vendor_ruby/1.8/rubygems/custom_require.rb:27:in `require’
    from /opt/local/lib/ruby/vendor_ruby/1.8/rubygems/remote_installer.rb:12
    from /opt/local/lib/ruby/vendor_ruby/1.8/rubygems/custom_require.rb:27:in `gem_original_require’
    from /opt/local/lib/ruby/vendor_ruby/1.8/rubygems/custom_require.rb:27:in `require’
    from /opt/local/lib/ruby/vendor_ruby/1.8/rubygems.rb:112:in `manage_gems’

    Any help would be MUCH appreciated!

  27. snowmaninthesun Says:

    If you run into a problem installing rubygems and are getting an error saying ruby could not installed correctly, try manually creating a blank /Library/Ruby folder, along with blank /usr/bin/ruby and /usr/bin/gem folders. (if you want to open the bin directory simply type open /usr/bin). I had to do this to get my install to work correctly, i also manually compiled the ruby library following directions from http://hivelogic.com/articles/2007/02/ruby-rails-mongrel-mysql-osx .

Leave a Reply

WP Theme & Icons by N.Design Studio
Entries RSS Comments RSS Log in