执行Bundle update rails时遭遇多Gem依赖兼容错误
Rails 4.2.5 依赖冲突问题处理
环境配置
- Ruby版本:ruby 3.1.4p223 (2023-03-30 revision 957bb7cb81) [i386-mingw32]
- Rails版本:4.2.5
- Gem版本:3.3.26
- Bundler版本:1.16.0
错误追踪信息
Bundler could not find compatible versions for gem "actionmailer": In Gemfile: exception_notification was resolved to 4.1.0, which depends on actionmailer (>= 3.0.4) rails (= 4.2.5) was resolved to 4.2.5, which depends on actionmailer (= 4.2.5) simple_token_authentication (~> 1.0) was resolved to 1.9.1, which depends on actionmailer (>= 3.2.6, < 5) Bundler could not find compatible versions for gem "actionpack": In Gemfile: haml-rails was resolved to 0.9.0, which depends on actionpack (>= 4.0.1) lograge was resolved to 0.3.2, which depends on actionpack (>= 3) rails (= 4.2.5) was resolved to 4.2.5, which depends on actionpack (= 4.2.5) redis-rails was resolved to 4.0.0, which depends on redis-actionpack (~> 4) was resolved to 4.0.0, which depends on actionpack (~> 4) simple_form was resolved to 3.1.0, which depends on actionpack (~> 4.0) simple_token_authentication (~> 1.0) was resolved to 1.9.1, which depends on actionpack (>= 3.2.6, < 5) Bundler could not find compatible versions for gem "activemodel": In Gemfile: globalize (~> 4.0.2) was resolved to 4.0.3, which depends on activemodel (>= 4.0.0, < 5) paperclip-meta was resolved to 1.2.0, which depends on paperclip (>= 3.0.2, < 5.0) was resolved to 4.2.1, which depends on activemodel (>= 3.0.0) rails (= 4.2.5) was resolved to 4.2.5, which depends on activemodel (= 4.2.5) rails-observers was resolved to 0.1.2, which depends on activemodel (~> 4.0) Bundler could not find compatible versions for gem "activerecord": In Gemfile: activerecord-import was resolved to 0.8.0, which depends on activerecord (>= 3.0) activerecord-nulldb-adapter was resolved to 0.3.8, which depends on activerecord (>= 2.0.0) activerecord-postgis-adapter was resolved to 2.2.2, which depends on activerecord (>= 4.0.0, < 4.2.0) annotate (>= 2.5.0) was resolved to 2.6.8, which depends on activerecord (>= 3.2, <= 4.3) ar-octopus was resolved to 0.8.5, which depends on activerecord (>= 3.2.0) delayed_job_active_record was resolved to 4.0.3, which depends on activerecord (>= 3.0, < 5.0) globalize (~> 4.0.2) was resolved to 4.0.3, which depends on activerecord (>= 4.0.0, < 5) rails (= 4.2.5) was resolved to 4.2.5, which depends on activerecord (= 4.2.5) activerecord-postgis-adapter was resolved to 2.2.2, which depends on rgeo-activerecord (~> 1.2) was resolved to 1.2.0, which depends on activerecord (~> 4.0) Bundler could not find compatible versions for gem "activesupport": In Gemfile: ar-octopus was resolved to 0.8.5, which depends on activesupport (>= 3.2.0) exception_notification was resolved to 4.1.0, which depends on activesupport (>= 3.0.4) haml-rails was resolved to 0.9.0, which depends on activesupport (>= 4.0.1) jbuilder was resolved to 2.2.16, which depends on activesupport (>= 3.0.0, < 5) lograge was resolved to 0.3.2, which depends on activesupport (>= 3) rails (= 4.2.5) was resolved to 4.2.5, which depends on activesupport (= 4.2.5) redis-rails was resolved to 4.0.0, which depends on redis-activesupport (~> 4) was resolved to 4.0.0, which depends on activesupport (~> 4) Bundler could not find compatible versions for gem "json": In Gemfile: aws-sdk (= 1.51.0) was resolved to 1.51.0, which depends on json (~> 1.4) capybara-webkit was resolved to 1.5.1, which depends on json httparty was resolved to 0.13.5, which depends on json (~> 1.8) raddocs was resolved to 0.4.0, which depends on json (~> 1.8, >= 1.8.1) rspec_api_documentation (~> 4.1.0) was resolved to 4.1.0, which depends on json (~> 1.4, >= 1.4.6) uglifier was resolved to 2.7.1, which depends on json (>= 1.8.0)
已尝试的解决方法(均未成功)
- 手动修改Gemfile中部分Gem版本,错误仍存在
- 执行
bundle update时,命令行陷入无限输出状态 - 删除
gemfile.lock后执行bundle update,出现Bundler版本不兼容错误:本地安装的是2.3.x版本,原gemfile.lock指定的是1.16.0版本
解决方案
1. 解决核心的activerecord依赖冲突
错误日志中最关键的冲突是activerecord-postgis-adapter 2.2.2仅支持activerecord <4.2.0,但Rails 4.2.5要求activerecord =4.2.5。需要升级该gem到支持Rails 4.2.x的版本:
在Gemfile中修改:
gem 'activerecord-postgis-adapter', '~> 2.3.0'
2.3.x系列的该gem明确支持Rails 4.2版本。
2. 解决json依赖冲突
aws-sdk 1.51.0依赖json ~>1.4,但uglifier、httparty等要求json >=1.8.0。可以采取两种方式:
- 方式一:升级aws-sdk到1.x系列中兼容json 1.8的版本,比如1.67.0:
gem 'aws-sdk', '~> 1.67.0' - 方式二:锁定json版本为1.8.6,这个版本同时满足所有依赖的要求:
gem 'json', '1.8.6'
3. 解决Bundler版本不兼容问题
由于项目原本使用Bundler 1.16.0,本地安装的2.3.x版本与老版本配置不兼容,建议使用项目指定的版本执行命令:
# 安装指定版本的Bundler gem install bundler -v 1.16.0 # 使用该版本执行安装 bundle _1.16.0_ install
如果后续需要升级Bundler,需确保所有gem兼容Bundler 2.x,但对于老项目优先使用原指定版本避免额外问题。
4. 验证其他依赖
globalize (~>4.0.2)的4.0.3版本兼容Rails 4.2.5,无需修改simple_token_authentication (~>1.0)的1.9.1版本兼容Rails <5,无需修改- 其他如haml-rails、lograge等gem的版本均兼容Rails 4.2.5,冲突是由核心依赖连锁导致的,解决上述问题后这些冲突会自动消失。
执行完上述修改后,执行bundle _1.16.0_ install即可完成依赖安装。
内容的提问来源于stack exchange,提问作者Brown Rice
相关产品推荐
相关产品推荐

