4

Somehow, my ruby gems got corrupted, and when I do

$ sudo gem update

I get:

ERROR:  While executing gem ... (Gem::Exception)
    Invalid spec cache file in /home/sawa/.gem/specs/api.rubygems.org%443/specs.4.8

I removed .gem, and reinstalled Ruby, but the problem persists. How can I repair this?

Andrew Marshall
  • 95,083
  • 20
  • 220
  • 214
sawa
  • 165,429
  • 45
  • 277
  • 381
  • Maybe try removing `~/.gem` again and `gem update --system` (as it may be a bug that was fixed in a newer RubyGems). Also, what Ruby version, RubyGems version, and any Ruby version manager (chruby, rbenv, RVM, etc.)? – Andrew Marshall Feb 09 '15 at 04:34
  • @AndrewMarshall Ruby is 2.2.0, Ruby gems is the one that came with it. I directly compiled from source and installed. – sawa Feb 09 '15 at 04:57

1 Answers1

7

First I suggest you save your gem list, just in case:

$ gem list > gems.txt

To verify that you're using the SPEC CACHE that you think you are:

$ gem env | grep "SPEC CACHE"
 - SPEC CACHE DIRECTORY: /home/sawa/.gem/specs

To see if you have any outdated sources:

$ gem sources

If you want to be careful, you can remove sources one by one, then re-add. (See code below)

Try pristine, though it will likely fail:

$ gem pristine --all

The harsh approach is to delete all the gem specs:

rm -rf /home/sawa/.gem/specs

The nuclear approach is to delete the gem directory, which you write that you've already tried:

rm -rf /home/sawa/.gem

My best guess is that one of your gem sources is returning an incorrect file, possibly a temporary problem. You can figure this out by removing all your gem sources.

$ gem sources -​-clear-all # clears the cache, but doesn't remove the source
$ gem sources --update  # probably will work, in which case you can stop now.

If clearing the sources doesn't work, then you can remove all and re-add:

$ gem sources 
$ gem sources --remove http://gems.rubyforge.org/
$ gem sources --remove http://gems.github.com
...etc ...
$ gem sources -​-update  # should work fine, because there are no sources
$ gem sources --add http://gems.rubyforge.org/
$ gem sources --update
$ gem sources --add http://gems.github.com
$ gem sources --update
...etc...
joelparkerhenderson
  • 34,808
  • 19
  • 98
  • 119
  • I think `gem sources --clear-all` and `gem sources --update` did it. That was the answer. Thanks. – sawa Feb 09 '15 at 05:01