错误:执行gem时...(TypeError)不兼容的编组文件格式(无法读取)

问题描述 投票:15回答:3

当我使用Ruby版本2.4.4和macOS Mojave运行bundle install时遇到了这个问题:

Fetching nokogiri 1.8.5
Installing nokogiri 1.8.5 with native extensions
Gem::Ext::BuildError: ERROR: Failed to build gem native extension.
ERROR: cannot discover where libxml2 is located on your system. please
make sure `pkg-config` is installed.

所以我跑了

xcode-select --install

但是当我运行gem install nokogiri时,我得到了以下输出:

ERROR:  While executing gem ... (TypeError)
    incompatible marshal file format (can't be read)
    format version 4.8 required; 60.33 given

我试着将我的cookies_serializer设置为:hybrid

Rails.application.config.action_dispatch.cookies_serializer = :hybrid

但没有任何效果。

有没有办法来解决这个问题?我现在甚至无法运行我的Rails服务器。

ruby-on-rails ruby rubygems nokogiri macos-mojave
3个回答
37
投票

感谢Morgan Jarry的回答,这对我有用:

我检查了我目前的消息来源,确实它们已经过时了:

gem sources

它印了

*** CURRENT SOURCES ***
http://gems.rubyforge.org/
http://gems.github.com

所以我运行这个脚本来删除它们并用https://rubygems.org/替换它们

gem sources -r  http://gems.rubyforge.org/
gem sources -r http://gems.github.com
gem sources -a https://rubygems.org/

21
投票

尝试删除你的~/.gemrc。我在Mojave上遇到了同样的问题,这解决了我的问题。


7
投票

您必须删除所有宝石来源并添加https://rubygems.org/。请注意,http://gems.rubyforge.org/http://gems.github.com永久死亡,应予以删除。您可以通过运行列出您的来源:

gem sources 

你应该得到这样的东西:

*** CURRENT SOURCES ***

//gems.rubyforge.org/
//gems.github.com

1)删除所有来源:

gem sources -r http://gems.rubyforge.org/
gem sources -r http://gems.github.com

2)添加正确的来源:

gem sources -a https://rubygems.org/

希望这可以帮助!

© www.soinside.com 2019 - 2024. All rights reserved.