You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

bundle exec无法识别vendor/bundle中已安装的Gem问题求助

问题

运行bundle exec puma -C config/puma.rb启动Rails项目时,抛出Bundler::GemNotFound: Could not find rake-12.3.3 in any of the sources错误。

背景

VM运行应用的镜像升级(伴随数据库升级)后出现该问题,应用本身核心内容未变更:

  • Ruby版本保持2.5.9p229不变
  • 所有Gem及对应版本未改动
  • RPM构建方式(FPM)未调整

当前配置

.bundle/config内容:

---
BUNDLE_FROZEN: "true"
BUNDLE_PATH: "vendor/bundle"

bundle env确认配置已被正确读取:

## Bundler settings

frozen
  Set for your local app (/var/app_name/current/.bundle/config): true
path
  Set for your local app (/var/app_name/current/.bundle/config): "vendor/bundle"

关键现象

  • vendor/bundle/ruby/2.5.0/gems目录下明确存在rake-12.3.3
  • bundle env输出的RubyGems Gem Path未包含vendor目录:
## Environment

Bundler       1.16.1
  Platforms   ruby, x86_64-linux
Ruby          2.5.9p229 (2021-04-05 revision 67939) [x86_64-linux]
  Full Path   /usr/bin/ruby
  Config Dir  /etc
RubyGems      2.7.6.3
  Gem Home    /usr/share/gems
  Gem Path    /var/app_name/.gem/ruby:/usr/share/gems:/usr/local/share/gems
  User Path   /var/app_name/.gem/ruby
  Bin Dir     /usr/bin
Tools
  Git         not installed
  RVM         not installed
  rbenv       not installed
  chruby      not installed

已尝试操作

  • 执行bundle config set --local path vendor/bundle,Gem Path无变化
  • 尝试BUNDLE_PATH="vendor/bundle" bundle env,Gem Path仍不包含vendor目录

解决方案

针对该问题,可按以下步骤排查修复:

  1. 显式指定BUNDLE_PATH运行命令
    镜像升级可能导致环境变量继承异常,直接在命令中指定路径:
BUNDLE_PATH=./vendor/bundle bundle exec puma -C config/puma.rb
  1. 检查并修复vendor目录权限
    镜像升级可能改变了目录权限,导致进程无法读取Gem文件:
# 查看权限
ls -ld /var/app_name/current/vendor/bundle
ls -l /var/app_name/current/vendor/bundle/ruby/2.5.0/gems/rake-12.3.3

# 调整权限(替换为运行puma的用户/组)
chown -R app_user:app_group /var/app_name/current/vendor/bundle
chmod -R 755 /var/app_name/current/vendor/bundle
  1. 重置bundle配置缓存
    旧缓存可能在镜像升级后失效,重新生成配置:
bundle config unset --local path
bundle config set --local path vendor/bundle
bundle install --frozen

注:因BUNDLE_FROZEN=true,bundle install会严格遵循Gemfile.lock,不会修改依赖版本。

  1. 排除RubyGems全局配置干扰
    镜像升级可能修改了全局Gem配置,临时取消全局GEM_PATH再运行:
unset GEM_PATH && bundle exec puma -C config/puma.rb
  1. 重新安装对应版本的bundler
    确认bundler版本与当前环境兼容,重新安装:
gem install bundler -v 1.16.1
bundle install --frozen

内容的提问来源于stack exchange,提问作者Thermatix

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.28 19:34:55