Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Corrupted ruby gem system

Tags:

ruby

rubygems

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?

like image 439
sawa Avatar asked Mar 18 '23 02:03

sawa


1 Answers

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...
like image 129
joelparkerhenderson Avatar answered Mar 23 '23 20:03

joelparkerhenderson