ERROR: While executing gem ... (TypeError) incompatible marshal file format (can't be read)
Asked Answered
B

5

23

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.

Bandeau answered 20/2, 2019 at 12:38 Comment(0)
B
42

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/
Bandeau answered 20/2, 2019 at 16:4 Comment(0)
B
25

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

Bigelow answered 20/2, 2019 at 13:27 Comment(3)
I'd like to add some nuance to this answer: ~/.gemrc contained a referce use rubyforge as a source. This was relevant 10 years ago, but these days gems live on rubygems.org, so you should have a reference to have https://rubygems.org as source instead.Oxidate
Thanks a lot Morgan ! I checked my current sources, they were outdated, so I removed them and replaced them with rubygems.org. Then I was able to install nokogori and run bundle install without any problem.Bandwidth
removing your .gemrc is **** NOT **** the solution. In fact a .gemrc can have a number of helpful controls like setting gem: --no-ri --no-rdoc :: the correct naswer to this question is the one with more votes below.Greeneyed
E
9

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!

Esperanzaespial answered 26/2, 2019 at 12:24 Comment(1)
This helped, I had gemcutter.org setup, removing which my problem went awayBunker
I
2

for me just browser cookie cleanup fixed all

Insured answered 23/2, 2022 at 14:32 Comment(3)
Your answer could be improved with additional supporting information. Please edit to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers in the help center.Catastrophism
This does not really answer the question. If you have a different question, you can ask it by clicking Ask Question. To get notified when this question gets new answers, you can follow this question. Once you have enough reputation, you can also add a bounty to draw more attention to this question. - From ReviewTamikotamil
This absolutely answers the question. While it could be wordier, so to speak, it's the right answer. After upgrading to macOS 13.1 I ran into this problem in an app that I sometimes have to go between ruby 2.7.5 and 3.1.2 based on a hotfix to an older version of the app. My gem sources were correct but it was the cookies. Cleared them and all good.Thorman
C
1

I had similar issue, server was responding well in one branchA while failing in branchB into the same project.

Solution:

  • Clear browser cache
  • Restart server
  • Hard refresh browser

That worked for me.

Possible root cause:
Rails version was updated in particular branch
In branchA it was Rails 6.0.4
while in branchB it was Rails 6.1.7.2

It may also help you!!!

Creaturely answered 30/6, 2023 at 11:58 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.