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

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/

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


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!