'Install newer version of bundler with bundler

If I change the version of bundler required in a Gemfile, and then type bundle, I get

Bundler could not find compatible versions for gem "bundler":
  In Gemfile:
    bundler (>= 1.10.2) ruby

  Current Bundler version:
    bundler (1.9.9)
This Gemfile requires a different version of Bundler.
Perhaps you need to update Bundler by running `gem install bundler`?
Could not find gem 'bundler (>= 1.10.2) ruby in any of the sources

Is it possible to ask bundler to install the new version of bundler, rather than typing in gem install bundler?



Solution 1:[1]

Seems like bundler can't bundle itself :)

So you have to run gem install bundler.

Solution 2:[2]

I think you can just run gem update bundler, right? It worked for me.

Solution 3:[3]

as of v1.14 there is now: bundle update --bundler

https://bundler.io/v2.0/man/bundle-update.1.html#OPTIONS

Solution 4:[4]

I have found bundle update --bundler does not work so well when a default Bundler version is set. This can result in warnings when running bundle. I know others above have mentioned using gem to install a later version of bundler so expanding off those answers here.

  1. You can run the following but this can present issues as it can break your local gems on your system as ALL of them are updated.

    gem update --system
    
  2. The following method is a much safer way of ensuring Bundler is updated

  • Get your gem environment and take note of INSTALLATION_DIRECTORY
    gem environment
    
  • Then run the following
    cd <INSTALLATION DIRECTORY>/specifications/default
    rm bundler-<old_default_version>.gemspec
    gem install --default bundler -v <new_default_version>
    
  1. If you have followed 2 and that still does not work, then run
    gem install bundler:<new_default_version>
    
    to ensure you your local repo is using the correct version

Solution 5:[5]

If gem install bundler does not upgrade your bundler version, then run gem install bundler --pre.

Solution 6:[6]

As of Bundler 2.3 (in combination with at least RubyGems 3.3), bundler can now fully upgrade itself by running

bundle update --bundler

This command has existed for a long time, but until now it only updated the version in your Gemfile.lock file to be the latest version installed on your system.

Now, it is able to fully upgrade your application to use the latest release of Bundler.

Note that other answers suggesting gem install bundler only partially fix the problem, because if you have a Gemfile.lock file locked to some old version and it is installed on your system, that version will still be respected even if you install the latest version globally with gem install bundler.

bundle update --bundler is the right way!

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1
Solution 2 ltrainpr
Solution 3 ellemenno
Solution 4 Alexander Swann
Solution 5 Daniel
Solution 6 deivid