Martin
Martin

Reputation: 637

How to specify minimum bundler version for Gemfile?

When my Gemfile is using :mri_20, and previous versions of bundler do not support that, is it a good idea to add

gem 'bundler', '~>1.3.5'

to the Gemfile? Is there a better way to enforce a minimum bundler version?

Upvotes: 16

Views: 7128

Answers (2)

Ting Yi Shih
Ting Yi Shih

Reputation: 876

Seems like bundler version is specified not in Gemfile, but in Gemfile.lock. Namely, you don't assume any bundler version for Gemfile until you start your installation of gems and the appearance of Gemfile.lock.

Reference: https://www.thomascountz.com/2020/09/18/specify-bundler-version

Upvotes: 0

Jon Cairns
Jon Cairns

Reputation: 11951

This won't have any affect on the bundler used to manage the gems in the Gemfile. The version of bundler that's used is the one that's available in your current ruby environment.

The best way to manage this is with gemsets - you can create a gemset with a known, working version of bundler and always switch to that gemset when working with that project.

To check the bundler version, run:

$ bundle --version
Bundler version 1.3.5

If you want to enforce the bundler version when running bundle install, put this at the top of the Gemfile:

# Gemfile
if Gem::Version.new(Bundler::VERSION) < Gem::Version.new('1.3.5')
  abort "Bundler version >= 1.3.5 is required"
end

Upvotes: 22

Related Questions