Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
545 views
in Technique[技术] by (71.8m points)

rubygems - Corrupted ruby gem system

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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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...

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...