56

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?

Andrew Grimm
  • 78,473
  • 57
  • 200
  • 338

6 Answers6

73

Seems like bundler can't bundle itself :)

So you have to run gem install bundler.

osman
  • 2,335
  • 18
  • 25
41

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

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

ellemenno
  • 712
  • 5
  • 11
  • 3
    This isn't correct, it only works if you happen to be in a directory that contains a Gemfile. – Andrew Koster Jan 27 '20 at 20:42
  • 1
    Specifically, it updates the `Gemfile.lock` version of bundler to the same as what you use to issue the command. This doesn't update bundler itself. – Benjamin W. Nov 18 '22 at 01:33
34

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

ltrainpr
  • 3,115
  • 3
  • 29
  • 40
  • 2
    `bundle update --bundler` won't work if you're in a directory with a Gemfile bundled by bundler 2, and you've currently only got bundler 1 installed. This works everywhere, and should be the correct answer. – jethro Mar 18 '20 at 14:34
  • 2
    Needed to run `bundle update --bundler` after this one to get my `Gemfile.lock` updated. – Vajk Hermecz Jun 28 '21 at 13:12
7

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!

deivid
  • 4,808
  • 2
  • 33
  • 38
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
Alexander Swann
  • 619
  • 5
  • 15
1

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

Daniel
  • 14,004
  • 16
  • 96
  • 156