2015-02-09 125 views
3

不知怎的,我的紅寶石的寶石被損壞了,當我做損壞紅寶石寶石系統

$ sudo gem update 

我得到:

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

我刪除.gem,並重新安裝紅寶石,但問題仍然存在。我該如何修復?

+0

也許嘗試刪除'〜/ .gem'一次'寶石更新--system' (因爲它可能是一個在新的RubyGems中修復的bug)。此外,Ruby版本,RubyGems版本和任何Ruby版本管理器(chruby,rbenv,RVM等)? – 2015-02-09 04:34:53

+0

@AndrewMarshall Ruby是2.2.0,Ruby的寶石是隨它一起來的。我直接從源代碼編譯和安裝。 – sawa 2015-02-09 04:57:39

回答

5

首先,我建議你保存你的寶石名單,以防萬一:

$ gem list > gems.txt 

要確認您使用的SPEC緩存你以爲你是:

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

要查看你有任何過時的來源:

$ gem sources 

如果你想要小心,你可以逐個刪除源,然後重新一個DD。 (請參見下面的代碼)

嘗試質樸,雖然它可能會失敗:

$ gem pristine --all 

殘酷的方法是刪除所有的寶石規格:

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

核的方法是刪除寶石目錄,你寫的,你已經嘗試過:

rm -rf /home/sawa/.gem 

我最好的猜測是o你的寶石來源的ne返回一個不正確的文件,可能是一個暫時的問題。你可以通過刪除所有的寶石來源來解決這個問題。

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

如果清除來源不工作,那麼你就可以刪除所有,然後重新添加:

$ 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... 
+0

我認爲'寶石來源 - 清除所有'和'寶石來源 - 更新'做到了。這是答案。謝謝。 – sawa 2015-02-09 05:01:16