Search code examples
rubybundlergemfile

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?


Solution

  • 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