腐蚀的红宝石宝石系统

saw*_*awa 3 ruby rubygems

不知何故,我的红宝石宝石被腐蚀了,当我这么做的时候

$ sudo gem update
Run Code Online (Sandbox Code Playgroud)

我明白了:

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

我删除.gem并重新安装了Ruby,但问题仍然存在.我该怎么修呢?

joe*_*son 6

首先,我建议您保存您的宝石列表,以防万一:

$ gem list > gems.txt
Run Code Online (Sandbox Code Playgroud)

要验证您是否正在使用您认为自己的SPEC CACHE:

$ gem env | grep "SPEC CACHE"
 - SPEC CACHE DIRECTORY: /home/sawa/.gem/specs
Run Code Online (Sandbox Code Playgroud)

要查看您是否有任何过时的来源:

$ gem sources
Run Code Online (Sandbox Code Playgroud)

如果您需要小心,可以逐个删除源,然后重新添加.(见下面的代码)

尝试pristine,虽然它可能会失败:

$ gem pristine --all
Run Code Online (Sandbox Code Playgroud)

严厉的方法是删除所有宝石规格:

rm -rf /home/sawa/.gem/specs
Run Code Online (Sandbox Code Playgroud)

核方法是删除你编写过的gem目录:

rm -rf /home/sawa/.gem
Run Code Online (Sandbox Code Playgroud)

我最好的猜测是你的一个宝石源正在返回一个不正确的文件,可能是一个临时问题.您可以通过删除所有宝石来源来解决这个问题.

$ 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.
Run Code Online (Sandbox Code Playgroud)

如果清除源不起作用,则可以删除所有并重新添加:

$ 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...
Run Code Online (Sandbox Code Playgroud)