Github pages installation: Jekyll -v output `require': cannot load such file -- google/protobuf_c (LoadError)
Asked Answered
T

1

6

I'm trying to follow this guide on setting up a GitHub page website. I installed Homebrew, chruby, and Jekyll following this jekyllrb.com tutorial.

When I run ruby -v I get ruby 3.1.2p20 (2022-04-12 revision 4491bb740a) [x86_64-darwin18]. When I run chruby -V I get chruby: 0.3.9. After installing Jekyll with gem install jekyll I get Successfully installed jekyll-4.3.1 Parsing documentation for jekyll-4.3.1 Done installing documentation for Jekyll after 0 seconds 1 gem installed.

But when I run jekyll -v (or any Jekyll command) I get a very long message with the following error:

<internal:/Users/my_username/.rubies/ruby-3.1.2/lib/ruby/3.1.0/rubygems/core_ext/kernel_require.rb>:85:in `require': dlopen(/Users/my_username/.gem/ruby/3.1.2/gems/google-protobuf-3.21.12-x86_64-darwin/lib/google/3.1/protobuf_c.bundle, 9): no suitable image found.  Did find: (LoadError)
    /Users/my_username/.gem/ruby/3.1.2/gems/google-protobuf-3.21.12-x86_64-darwin/lib/google/3.1/protobuf_c.bundle: cannot load 'protobuf_c.bundle' (load command 0x80000034 is unknown)
    /Users/my_username/.gem/ruby/3.1.2/gems/google-protobuf-3.21.12-x86_64-darwin/lib/google/3.1/protobuf_c.bundle: cannot load 'protobuf_c.bundle' (load command 0x80000034 is unknown) - /Users/my_username/.gem/ruby/3.1.2/gems/google-protobuf-3.21.12-x86_64-darwin/lib/google/3.1/protobuf_c.bundle

I spent hours looking at what this error means and found very specific (to some version of Ruby or other libraries) questions like Ruby 2.7.2 google/protobuf_c problem (M1), Ruby: Gem version 3.11.2 doesn't load on Ruby 2.7, and many others.

It's the first time I even hear about Ruby or Jekyll or anything else here and I can't figure out how to properly install these to just make a website on GitHub. I also tried to install Ruby using rvm instead of chruby but that gave the same error. I also tried to install different versions of Ruby, like 3.1.3 and 3.2.0.

Tepefy answered 30/12, 2022 at 8:4 Comment(0)
E
5

When gems have native extensions that need to be compiled it's possible for the gem author to build the extensions in advance and include them in the package so that the gem can install faster than if it were being compiled from scratch. Unfortunately Google has broken this implementation repeatedly.

This has been a problem for about two years with google-protobuf. Google has periodically fixed it and broken it again. They also periodically claim to understand the problem without understanding it and claim to have fixed it without fixing it. And their GitHub issues frequently pass the buck when they're the only ones that can fix it.

Anytime you're dealing with google-protobuf on macOS it's best to ensure that you are compiling it from scratch. This can be done with the --platform argument:

gem install --platform ruby google-protobuf

The platform ruby means don't use any pre-compiled binaries and force compilation from source.

The platform x86_64-darwin means use the pre-compiled binaries for macOS with Intel processors. That's the version that the gem installer identified for your system and used automatically but the error no suitable image found is a macOS error that means this library was not compiled in a way that I can understand.

Erysipelas answered 6/1, 2023 at 21:22 Comment(4)
Thanks, in my case sudo gem uninstall google-protobuf was necessary, before sudo gem install google-protobuf -v 3.21 --platform=ruby which -v 3.21 is the version required by jekyll 4.3.1 .Threedimensional
There is almost no circumstance under which gem should ever be run with sudo. I'm leaving this comment for future readers; generally, if you're using sudo gem then you're doing something wrong and should make sure you know the reason that you have to use sudo before trying it.Erysipelas
I almost never run a command with sudo for the first time, and thank you for the heads up, in that case I did receive permission error and adding sudo solved the error. it seems there is a better way to install ruby and rubygems at mac m1, but I just need them for jekyll, and thanks to you is working now.Threedimensional
Your answer is a life saver. Thank youKesler

© 2022 - 2024 — McMap. All rights reserved.