How to fix that Rubygems mess on Leopard

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! gem list > ~/Desktop/installed_gems.txt

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!):sudo rm -r /System/Library/Frameworks/Ruby.framework/
sudo rm -r /Library/Ruby
sudo rm /usr/bin/ruby
sudo rm /usr/bin/gem

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: sudo port install rb-rubygems

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

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 sudo gem install rails -v 1.2.6
  • For Rails 2 (aka latest-and-greatest), run sudo gem install rails

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: sudo gem install RedCloth acts_as_ferret mongrel fcgi capistrano ruby-openid ferret dnssd hpricot sqlite3-ruby libxml-ruby termios

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!

Trackback URL

, , , , , , , , ,

37 Comments on "How to fix that Rubygems mess on Leopard"

  1. Kevin
    14/12/2007 at 7:24 pm Permalink

    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
    15/12/2007 at 1:07 am Permalink

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

  3. Jason
    15/12/2007 at 2:49 am Permalink

    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
    15/12/2007 at 4:43 pm Permalink

    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
    15/12/2007 at 8:25 pm Permalink

    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
    15/12/2007 at 8:39 pm Permalink

    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
    16/12/2007 at 3:34 am Permalink

    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. dy
    16/12/2007 at 3:28 pm Permalink

    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

  9. Carl Mercier
    16/12/2007 at 3:38 pm Permalink

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

  10. dy
    16/12/2007 at 4:29 pm Permalink

    oops.
    I forgot it,thanks

  11. Gary Haran
    17/12/2007 at 6:10 pm Permalink

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

  12. James O'Kelly
    20/12/2007 at 8:14 am Permalink

    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

  13. Carl Mercier
    20/12/2007 at 12:17 pm Permalink

    James,

    Try pasting the whole error message. It will help.

  14. Aris
    21/12/2007 at 11:35 am Permalink

    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

  15. Aris
    21/12/2007 at 11:42 am Permalink

    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

  16. Laurent Sansonetti
    21/12/2007 at 4:30 pm Permalink

    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.

  17. macournoyer
    27/12/2007 at 6:49 pm Permalink

    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

  18. Philippe Rathe
    29/12/2007 at 9:14 pm Permalink

    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!

  19. Philippe Rathe
    29/12/2007 at 9:17 pm Permalink

    @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.

  20. Mike
    14/02/2008 at 4:44 pm Permalink

    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

  21. Andy
    16/02/2008 at 3:42 am Permalink

    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.

  22. Andy
    16/02/2008 at 3:04 pm Permalink

    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?

  23. Danyel Lawson
    08/03/2008 at 1:32 pm Permalink

    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

  24. Danyel Lawson
    09/03/2008 at 5:22 pm Permalink

    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.

  25. noah
    08/04/2008 at 3:17 pm Permalink

    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!

  26. snowmaninthesun
    17/05/2008 at 2:50 am Permalink

    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 .

  27. Anon Ymous
    08/01/2009 at 11:22 am Permalink

    Thanks!

  28. Stephan
    16/02/2009 at 12:24 pm Permalink

    Hi,

    lile macournoyer (see above) TextMate stopped working:
    When trying to run a Ruby script I bump into this:/tmp/temp_textmate.2iRNDE: line 6: : command not found

    I guess it has to do with how TextMate finds the Ruby to run.
    Any hint how to fix this is greatly appreciated.

    Other than this: Thanks & works really fine.

  29. Chris
    07/03/2009 at 5:29 pm Permalink

    Fantastic tutorial. Thank you!

  30. Simon
    11/03/2009 at 9:12 am Permalink

    Just a big thanks, after many wasted hours trying to fix the mess.

  31. Rob Olson
    26/04/2009 at 3:51 am Permalink

    If you use MacVim you should not remove the OS X bundled Ruby framework (/System/Library/Frameworks/Ruby.framework/). Removing it will break MacVim.

  32. Ryan JM
    19/05/2009 at 3:35 pm Permalink

    THANK YOU!! That helped a lot. Just follow the instructions and got everything to work. Amazing.

  33. Max Howell
    28/06/2009 at 4:09 pm Permalink

    It would be a mistake for Apple to bundle MacPorts. It is self contained system. It duplicates the entire Unix library stack. Two copies of libz, libm, libcrypto etc. on every Mac would be stupid.

    And anyway it wouldn’t achieve anything towards helping with your problem if they did. The solution to your problem is to fix rubygems on os x, not install and entirely different packaging system to install another packaging system–that’s crazy.

    Your attack makes no sense either. Yes Apple fucked up somehow and updating ruby gems doesn’t work, but all they did was bundle RubyGems (badly) with OS X, there was no “wheel” that got “reinvented”. If anything RubyGems is reinventing the wheel by making yet another bloody packaging system.

  34. Max Howell
    28/06/2009 at 4:13 pm Permalink

    Not that I dislike MacPorts I should add. I have used it for years.

  35. Charlie
    21/12/2009 at 6:30 pm Permalink

    hey, I followed your guide, and I got gems working great, but now when I write things in my IDE RadRails or NetBeans, it wont find any VM or anything, so, its greatly frustrating me, and I have installed it time and time again and am getting kinda frustrated with it all. Any help or suggestions on what to do?

Trackbacks

  1. [...] Carl Mercier’s blog » Blog Archive » How to fix that Rubygems mess on Leopard Need help with fixing ...

  2. [...] (1 , 2) SHARETHIS.addEntry({ title: "Ruby, gems and Tweets on the desktop with GeekTool", url: [...]

Hi Stranger, leave a comment:

ALLOWED XHTML TAGS:

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Subscribe to Comments