Read more

How to update RubyGems binary for all installed rubies

Arne Hartherz
September 03, 2015Software engineer at makandra GmbH

To update your Rubygems to the latest available version, type the following:

 gem update --system
Illustration online protection

Rails Long Term Support

Rails LTS provides security patches for old versions of Ruby on Rails (2.3, 3.2, 4.2 and 5.2)

  • Prevents you from data breaches and liability risks
  • Upgrade at your own pace
  • Works with modern Rubies
Read more Show archive.org snapshot

Note that you have a separate Rubygems installation for each Ruby version in your RVM or rbenv setup. Updating one does not update the others.

Ruby 1.8.7

If you are using Ruby 1.8.7 you cannot use the latest version of Rubygems. Type the following to get the latest version that is compatible with 1.8.7:

 gem update --system 1.8.30

Updating RubyGems for all installed Ruby versions

Because of occasional security issues in RubyGems binaries, you should keep them updated across all Rubies on your machines. [1]

Here is how to do that in batch.
Afterwards, list your installed versions to confirm it worked.

rbenv

Here is a one-line bash script that will update all, and fall back to 1.8.30 for Ruby 1.8.7:

for i in `rbenv versions --bare`; do rbenv shell $i; echo $i; if [ ${i:0:4} = 1.8. ]; then gem update --system 1.8.30; else gem update --system; fi; done; rbenv shell --unset;

You could also use rbenv-each for this.

RVM

Use RVM's rvm all do:

rvm all do gem update --system

As mentioned above, the latest version will not work on Ruby 1.8.7. Manually switch to all such versions and use the compatible version like this:

rvm use 1.8.7
rvm rubygems latest-1.8 --force

[1] Note that Ruby 1.8.7 can not use the latest version or it would throw a NoMethodError: undefined method source_index for Gem:Module. We use the latest compatible version instead.

Posted by Arne Hartherz to makandra dev (2015-09-03 11:52)