A Fresh Cup is Mike Gunderloy's software development weblog, covering Ruby on Rails and whatever else I find interesting in the universe of software. I'm a full-time software developer: most of my time in recent years has been spent writing Rails, though I've dabbled in many other things and like most people who have been writing code for decades I can learn new stuff as needed.

Currently I'm unemployed and starting to look around for my next opportunity as a senior manager, team lead, or lead developer. Drop me a comment if you're interested or email MikeG1 [at] larkfarm.com.

« Double Shot #320 | Main | Rails 2.2 Change: Private Methods on Association Proxies are Private »

Rails 2.1.2 and 2.2RC1: Update Your RubyGems

There's a mismatch between the most recent Rails releases (2.1.2 and 2.2RC1) and older versions of RubyGems. Judging by what I've seen in various discussion fora, this is well on the way to being a FAQ. It's made more fun by the facts that
  • The error message doesn't implicate RubyGems

  • You may think you're up-to-date on RubyGems when you're not

  • If you're affected, you'll see this message when you try to run script/generate in a Rails application:

    [sourcecode language='ruby']
    undefined method empty?' for /_generator$/:Regexp

    If you see this, don't panic. It just means you need a newer RubyGems release. I'm not sure how current you need to be, but 1.1.1 is definitely too old. As I write this, 1.3.0 is current.

    Now, in theory, to update to the latest version of RubyGems, you just need to run

    [sourcecode language='ruby']
    sudo gem update --system

    But - depending on what version of RubyGems you have installed, running that command may lie and tell you that you have nothing to update. If you're currently on RubyGems 1.1 or 1.2, you need to run a different set of commands to update RubyGems:

    [sourcecode language='ruby']
    sudo gem install rubygems-update
    sudo update_rubygems

    You can check your current RubyGems version with

    [sourcecode language='ruby']
    gem -v
    If it reports 1.3.0 or later, you should be good to use the recent Rails releases.

    Reader Comments (10)

    Bless you, this post saved my bacon.

    November 4, 2008 | Unregistered CommenterChris Luebcke

    Works like a charm, thank you.

    November 6, 2008 | Unregistered CommenterMario Zigliotto

    Thanks for your hint!

    November 9, 2008 | Unregistered CommenterAdrian

    bah! all hassle in each upgrade...

    November 14, 2008 | Unregistered Commenterdeman

    This is the clearest explanation of how to handle this error on the net. Thanks for taking the time to do it!

    November 15, 2008 | Unregistered Commenterjeman

    Thanks for the tip, much appreciated!

    November 17, 2008 | Unregistered CommenterIphan

    Thank You, Mike! Helped me out (I had RubyGems 1.2).

    November 28, 2008 | Unregistered CommenterHarry

    Thank you! I couldn't find this info. on the RubyGems site!

    December 8, 2008 | Unregistered CommenterDavid Rivers

    I am current using Ubuntu 8.10. For me, if I ran the commands, rubygems would stay at 1.2 even though it looked like it "updated successfully"

    If you are trying to update ruby gems on Ubuntu, you may need to install it manually. Sam Ruby has a good set of instructions. See http://intertwingly.net/blog/2008/11/23/RubyGems-1-3-1-on-Ubuntu-8-10

    December 31, 2008 | Unregistered CommenterBen Wagaman

    Hi, I thought i was getting close to success upon finding this thread.
    After your alternative update commands, my terminal reports that i now have v1.3.3 but xcode debugger still tells me i have 1.0.1.

    Due to installation issues with ruby/rails et al, on two different mac's I haven't been able to get past step one of a single tutorial.

    Please can someone point me in the right direction!?!

    Kindest regards


    May 27, 2009 | Unregistered Commenterjez

    PostPost a New Comment

    Enter your information below to add a new comment.
    Author Email (optional):
    Author URL (optional):
    Some HTML allowed: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <code> <em> <i> <strike> <strong>