Search code examples
ruby-on-railsrubyrubygemsbundleractivesupport

Force Bundler to install gems supported by the local Ruby version


Is there a way of installing the latest supported version of a dependency without specifying it?

I'm having issues with the activesupport gem. The latest version (5.0.0.1) supports Ruby >= 2.2.2. If I'm specifying that I require the gem like this '~> 4.2' Bundler will try to install version 5 even if I'm on Ruby 2.0. Specifying the exact version 4.2.7.1 or setting a maximum '~> 4.2', '< 5' works, except when using the gem with Rails 5.

Is there a way to manage gem versions based on the current Ruby version?


Solution

  • Apparently the new version of Bundler will do this for you automatically. I found this comment from André Arko that mentions this is already included in the latest RC version.

    I specified Ruby '2.0' in my Gemfile, installed Bundler with gem install bundler --pre (it installed bundler-1.13.0.rc.2) and bundle install successfully installed activesupport 4.2.7.1.

    With Bundler 1.12.5 I was getting the following error:

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