jaibhavaya
jaibhavaya

Reputation: 108

Bundler Version not AutoSwitching in the Presence of Gemfile.lock

After upgrading bundler, I am receiving an error of:

You must use Bundler 2 or greater with this lockfile.

I have both version 1.17.3 and 2.0.2 installed locally. I was under the impression based on what I have read that this is supposed to auto switch the version based on what the Gemfile.lock denotes. This doesn't appear to be happening.

Below is some useful info about my environment.

# cat Gemfile.lock 
GEM
  remote: https://rubygems.org/
  specs:
    domain_name (0.5.20190701)
      unf (>= 0.0.5, < 1.0.0)
    http-cookie (1.0.3)
      domain_name (~> 0.5)
    mime-types (3.2.2)
      mime-types-data (~> 3.2015)
    mime-types-data (3.2019.0331)
    netrc (0.11.0)
    pp (0.1.1)
    rest-client (2.0.2)
      http-cookie (>= 1.0.2, < 2.0)
      mime-types (>= 1.16, < 4.0)
      netrc (~> 0.8)
    terminal-table (1.8.0)
      unicode-display_width (~> 1.1, >= 1.1.1)
    unf (0.1.4)
      unf_ext
      unf_ext (0.0.7.6)
    unicode-display_width (1.6.0)

PLATFORMS
  ruby

DEPENDENCIES
  pp (~> 0.1.1)
  rest-client (~> 2.0)
  terminal-table (~> 1.8)

BUNDLED WITH
   2.0.2
# bundle install
You must use Bundler 2 or greater with this lockfile.
# gem list | grep bundler
bundler (2.0.2, default: 1.17.3, 1.16.6)

Upvotes: 0

Views: 196

Answers (2)

jaibhavaya
jaibhavaya

Reputation: 108

It turns out this was an issue with the ruby docker image we used. It utilizes the environment variable $BUNDLER_VERSION which overrides the bundler auto switching. This was solved by upgrading to a newer image.

It could have also been solved by explicitly setting BUNDLER_VERSION to the version needed for the Gemfile.

Upvotes: 0

tadman
tadman

Reputation: 211560

bundle -v tells you which one you're using now, and if it isn't 2.0 then you'll get this error.

It's not (yet?) smart enough to load a different version of bundler depending on the Gemfile. Normally you'd make it mach with bundle exec, but you've got a chicken-and-egg problem here then, as that command must succeed before the correct Bundler version can load, but it can't because it errors out early.

Remove all versions of Bundler and reinstall just 2.x.

Upvotes: 1

Related Questions