【问题标题】:Force Bundler to install gems supported by the local Ruby version强制 Bundler 安装本地 Ruby 版本支持的 gem
【发布时间】:2016-09-07 09:30:20
【问题描述】:

有没有办法在不指定的情况下安装最新支持的依赖版本?

我遇到了activesupport gem 的问题。最新版本 (5.0.0.1) 支持 Ruby >= 2.2.2。如果我指定我需要像 '~> 4.2' 这样的 gem,即使我在 Ruby 2.0 上,Bundler 也会尝试安装版本 5。指定确切版本 4.2.7.1 或设置最大值 '~> 4.2', '< 5' 有效,除非在 Rails 5 中使用 gem。

有没有办法根据当前的 Ruby 版本管理 gem 版本?

【问题讨论】:

    标签: ruby-on-rails ruby rubygems bundler activesupport


    【解决方案1】:

    显然,新版本的 Bundler 会自动为您执行此操作。 我从 André Arko 那里找到了this comment,其中提到这已包含在最新的 RC 版本中。

    我在我的 Gemfile 中指定了Ruby '2.0',用gem install bundler --pre 安装了Bundler(它安装了bundler-1.13.0.rc.2),bundle install 成功安装了activesupport 4.2.7.1。

    使用 Bundler 1.12.5 我收到以下错误:

    An error occurred while installing activesupport (5.0.0.1), and Bundler cannot continue.
    

    【讨论】:

      【解决方案2】:

      请注意,虽然需要更多手动操作,但您也可以在 Gemfile 中包含逻辑:

      if RUBY_VERSION <  "2.2.2"
        gem "activesupport", "4.2.7.1"
      else
        gem "activesupport", "5.0.0.1"  
      end
      

      【讨论】:

      • 这是一个gem依赖,所以必须放在gemspec中。
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2015-03-03
      • 2013-01-13
      • 2022-11-10
      • 1970-01-01
      • 2016-11-09
      • 2022-08-14
      • 1970-01-01
      相关资源
      最近更新 更多