240

I need to upgrade gems to 1.8 i tried installing the respective debian packages but it seems its not getting upgraded

anujm@test:~$ dpkg -l |grep -i rubygem
ii  rubygems                               1.3.5-1ubuntu2                                  package management framework for Ruby libraries/applications
ii  rubygems-lwes                          0.8.2-1323277262                                LWES rubygems
ii  rubygems1.8                            1.3.5-1ubuntu2                                  package management framework for Ruby libraries/applications
ii  rubygems1.9                            1.3.5-1ubuntu2                                  package management framework for Ruby libraries/applications
anujm@test:~$ 


anujm@test:~$ gem
gem     gem1.8  gem1.9  
anujm@test:~$ sudo gem1.8 install serve
ERROR:  Error installing serve:
        multi_json requires RubyGems version >= 1.3.6
anujm@test:~$
Anuj
  • 9,222
  • 8
  • 33
  • 30
  • 2
    Just to clarify, your question is on how to update Rubygems itself — not any particular gem managed by rubygems. – Michael Aug 29 '16 at 18:03

9 Answers9

504

Install rubygems-update

gem install rubygems-update
update_rubygems
gem update --system

run this commands as root or use sudo.

Sacx
  • 6,276
  • 4
  • 22
  • 29
  • 1
    i am getting this exception when i follow ue suggestion gem update --system is disabled on Debian. RubyGems can be updated using the official Debian repositories by aptitude or apt-get. – Anuj Nov 30 '12 at 09:18
  • 3
    Here because of problems with unicode gem (https://github.com/blackwinter/unicode/issues/5): after having run answer's solution I had to run `gem pristine unicode` which re-built the gem and made it usable. – reallynice Jan 08 '14 at 10:43
  • Works greate to update the rubygems on Debian system. Thanks! – Melroy van den Berg Jul 09 '14 at 09:31
  • I did this, and it seemed to uninstall all my gems! They're easy to reinstall, but that surprised me. – Jon Carter Aug 16 '14 at 01:31
  • I did this and all the gems installed on my machine got erased, and I had to install them all over again. Any idea why it happens? – IcyFlame Dec 22 '14 at 11:06
  • 1
    Thanks, it helped me to install `minitest` on an NFS partition cf. https://github.com/rubygems/rubygems/issues/1161 – Thom4 Jun 13 '15 at 11:11
  • @Sacx, hamza(my teammate) want to kiss your forhead :) for this answer – Abdul Rauf Feb 01 '16 at 10:48
  • 19
    `rubygems-update` is installed by default. So, it's the matter of running just `gem update --system`. – dskecse Jul 12 '16 at 14:22
  • 5
    Usually you will never want to run this command as `sudo`. That will upgrade the system ruby. Consider using `rvm` or `rbenv` – Hendrik Feb 07 '17 at 15:55
  • Can anyone suggest a way to lock the RubyGems version for Docker? These updates would be applied once but leave the image unchanged. – Archonic Mar 05 '19 at 05:00
  • Why would you want to run this as `root`? – gen Apr 23 '20 at 17:21
  • `rubygems-update` can be missing. `gem install rubygems-update` was failing for me. Response was `➜ gem update —system zsh: command not found: gem update`. Running the commands fixed it, although the latter wasn't necessary at least at this time, maybe because a fresh install. macOS Big Sur on a 2013 MBP – Greg Jan 13 '21 at 17:53
  • `rubygems-update` seems broken on Ubuntu 18.04:`/usr/lib/ruby/vendor_ruby/rubygems/defaults/operating_system.rb:43:in ': uninitialized constant Gem::BasicSpecification (NameError)` – aggregate1166877 Aug 10 '21 at 01:46
  • Isn't update_rubygems and gem update --system the same? Both update the RubyGem system software, right? – Martin Braun Apr 25 '23 at 21:38
64

You can update all gems by just performing:

sudo gem update

Potherca
  • 13,207
  • 5
  • 76
  • 94
Frank
  • 1,311
  • 2
  • 13
  • 15
25

Or:

gem update `gem outdated | cut -d ' ' -f 1`
jvc26
  • 6,363
  • 6
  • 46
  • 75
24

I found other answers to be inaccurate/outdated. Best is to refer to the actual documentation.

Short version: in most cases gem update --system will suffice.

You should not blindly use sudo. In fact if you're not required to do so you most likely should not use it.

retro
  • 3,765
  • 2
  • 20
  • 37
thisismydesign
  • 21,553
  • 9
  • 123
  • 126
14

You can update gem to any specific version like this,

gem update --system 'version'

gem update --system '2.3.0'
Aravin
  • 6,605
  • 5
  • 42
  • 58
  • 3
    you command doesn't work on distribution based on debian gem update --system "2.1.0" ERROR: While executing gem ... (RuntimeError) gem update --system is disabled on Debian, because it will overwrite the content of the rubygems Debian package, and might break your Debian system in subtle ways. The Debian-supported way to update rubygems is through apt-get, using Debian official repositories. If you really know what you are doing, you can still update rubygems by setting the REALLY_GEM_UPDATE_SYSTEM environment variable, but please remember that this is completely unsupported by Debian. – jeff Mar 03 '16 at 18:27
6

For me it sufficed to simply run

gem update
Klas Mellbourn
  • 42,571
  • 24
  • 140
  • 158
5

I wouldn't use the debian packages, have a look at RVM or Rbenv.

lucas clemente
  • 6,255
  • 8
  • 41
  • 61
4

To update just one gem (and it's dependencies), do:

bundle update gem-name

But to update just the gem alone (without updating it's dependencies), do:

bundle update --source gem-name
alper
  • 2,919
  • 9
  • 53
  • 102
Kaka Ruto
  • 4,581
  • 1
  • 31
  • 39
0

If you're using RVM, the command below helped me a lot when upgrading from a very very old rubygems (eg 1.3.7) that defies the more current update commands mentioned in the other responses in this thread.

rvm rubygems <version>
janechii
  • 1,055
  • 1
  • 11
  • 26