ERROR: While executing gem … (TypeError) incompatible marshal file format (can't be read)

我的未来我决定 提交于 2019-12-31 19:30:08

问题


I encountered this issue when I run bundle install with Ruby version 2.4.4 and macOS Mojave:

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.

So I ran

xcode-select --install

But then when I run gem install nokogiri I got the following output:

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

I tried to set my cookies_serializer to :hybrid:

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

But nothing worked.

Is there a way to fix this? I cannot even run my Rails server right now.


回答1:


Thanks to Morgan Jarry answer, this is what worked for me :

I checked my current sources and indeed they were outdated :

gem sources

It printed

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

So I ran this script to remove them and replaced them with https://rubygems.org/

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



回答2:


Try removing your ~/.gemrc. I had the same problem on Mojave and this solve my problem.




回答3:


You have to remove all the gem sources you have and add https://rubygems.org/ instead. Note that http://gems.rubyforge.org/ and http://gems.github.com are permanently dead and should be removed. You can list your sources by running:

gem sources 

You should get something like this:

*** CURRENT SOURCES ***

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

1) Delete all sources:

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

2) Add the right source:

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

Hope this helps!



来源:https://stackoverflow.com/questions/54786580/error-while-executing-gem-typeerror-incompatible-marshal-file-format-can

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!