已安装google-protobuf gem仍无法被Jekyll识别的问题求助
解决Bundler无法找到google-protobuf依赖的问题
问题背景
使用非Mac系统自带的Ruby环境,which ruby与which gem路径一致,但运行jekyll serve时Bundler提示找不到google-protobuf-3.25.2。尝试bundle install和gem install google-protobuf后仍无效,终端输出显示gem已安装但扩展未构建,Bundler无法识别该依赖。
终端关键输出:
username@MBP repo % gem install google-protobuf Building native extensions. This could take a while... Successfully installed google-protobuf-3.25.2 username@MBP repo % bundle exec jekyll serve Could not find google-protobuf-3.25.2 in locally installed gems username@MBP repo % jekyll server Ignoring google-protobuf-3.25.2 because its extensions are not built. Try: gem pristine google-protobuf --version 3.25.2
解决方案
1. 修复google-protobuf的原生扩展
终端明确提示扩展未构建,先执行以下命令重新编译扩展:
gem pristine google-protobuf --version 3.25.2
该命令会重置并重新构建gem的原生扩展,解决扩展未生成导致的忽略问题。
2. 将gem纳入Bundler依赖管理
直接通过gem install安装的包可能未被项目的Gemfile或Gemfile.lock记录,执行以下命令将指定版本的google-protobuf添加到项目依赖:
bundle add google-protobuf --version 3.25.2
这会自动更新Gemfile和Gemfile.lock,让Bundler能识别到已安装的gem。
3. 同步依赖并启动Jekyll
执行bundle install确保所有依赖与锁文件一致,再启动Jekyll服务:
bundle install bundle exec jekyll serve
备选方案(若上述步骤无效)
- 删除项目根目录下的
Gemfile.lock文件,重新执行bundle install,让Bundler重新生成依赖锁文件,规避潜在的版本冲突。 - 检查Gemfile中是否存在其他依赖与google-protobuf-3.25.2版本冲突,尝试调整版本号或移除冲突依赖。
内容的提问来源于stack exchange,提问作者Jakob Muel
相关产品推荐
相关产品推荐

