2

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?

Sebastian
  • 2,154
  • 1
  • 26
  • 42

2 Answers2

1

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.
Sebastian
  • 2,154
  • 1
  • 26
  • 42
0

Note that while a bit more manual, you can also include logic in your Gemfiles:

if RUBY_VERSION <  "2.2.2"
  gem "activesupport", "4.2.7.1"
else
  gem "activesupport", "5.0.0.1"  
end
Ginty
  • 3,483
  • 20
  • 24