Bundler: can't find gem bundler (>= 0.a) with executable bundle (Gem::GemNotFoundException) during bundle install with gem

Bundler version 2 introduced a new feature to automatically use the version of Bundler specified in the Gemfile.lock of your project. Thus, if you have an existing Gemfile.lock with a line like this at the bottom

BUNDLED WITH
   1.17.3

Bundler will try to run with a Bundler version < 2.0. Since you just have Bundler 2.0.1 (and Rubygems >= 2.7.0) installed, this fails with this rather unhelpful error message.

To fix this, you could

  • remove the lines from your Gemfile.lock and to use bundler 2.x everywhere from now on, or
  • install a bundler 1.x version with gem install bundler -v '< 2.0' to use the appropriate version as specified by your Gemfile.lock.

More information about this can be found on the Bundler blog.


As per the description mentioned in the post , before running the below mentioned command:

bundle install

in the script, you need to run the below command:

gem install bundler

So, the sequence of commands to work would be:

gem install bundler
bundle install

Update the bundler command if if does not work to:

 gem install bundler -v '1.17.3'

Reason for the break in functionalities in bundler 2.0 is given in below mentioned link:

https://bundler.io/blog/2019/01/04/an-update-on-the-bundler-2-release.html


I couldn’t even do bundle -v. This sorted it out:

gem update --system

Got the info from here (similar problem): find_spec_for_exe': can't find gem bundler (>= 0.a) (Gem::GemNotFoundException)

Probably some version mismatch between ruby + gem + bundler