How to downgrade rubygems

Today I ran into a problem where my team’s build system had made gem update --system a part of our packaging script. After the release of Ruby 2.0 all of our 1.9 apps rather suddenly became obsolete and Rubygems 2 failed to bundle properly.

Here’s how we downgraded to Rubygems 1.8.25:

rubygems=`ruby --disable-gems -S gem which rubygems`
echo $rubygems
rm $rubygems
rm -rf `dirname $rubygems`/rubygems

Here’s the error I saw that let me know my Rubygems version was wrong:

NameError: uninitialized constant Gem::Builder

And here’s what happened when I tried to downgrade the normal way:

$ gem update --system 1.8.25
Updating rubygems-update
ERROR:  While executing gem ... (Gem::Package::PathError)
    installing into parent path /usr/ruby19/lib64/ruby/gems/1.9.1/gems/rubygems-update-1.8.25/.autotest of /usr/ruby19/lib64//ruby/gems/1.9.1/gems/rubygems-update-1.8.25 is not allowed