Bundler: You must use Bundler 2 or greater with this lockfile

Pedro picture Pedro · Nov 9, 2018 · Viewed 67k times · Source

I'm working with heroku and every time I try to push my app this message shows out:

remote: Compressing source files... done.
remote: Building source:
remote: 
remote: -----> Ruby app detected
remote: 
remote:  !
remote:  !     You must use Bundler 2 or greater with this lockfile.
remote:  !
remote: /tmp/d20181109-104-g861yi/bundler-1.15.2/gems/bundler-1.15.2/lib/bundler/lockfile_parser.rb:108:in `warn_for_outdated_bundler_version': You must use Bundler 2 or greater with this lockfile. (Bundler::LockfileError)
remote:     from /tmp/d20181109-104-g861yi/bundler-1.15.2/gems/bundler-1.15.2/lib/bundler/lockfile_parser.rb:95:in `initialize'
remote:     from /app/tmp/buildpacks/b7af5642714be4eddaa5f35e2b4c36176b839b4abcd9bfe57ee71c358d71152b4fd2cf925c5b6e6816adee359c4f0f966b663a7f8649b0729509d510091abc07/lib/language_pack/helpers/bundler_wrapper.rb:130:in `new'
remote:     from /app/tmp/buildpacks/b7af5642714be4eddaa5f35e2b4c36176b839b4abcd9bfe57ee71c358d71152b4fd2cf925c5b6e6816adee359c4f0f966b663a7f8649b0729509d510091abc07/lib/language_pack/helpers/bundler_wrapper.rb:130:in `block in parse_gemfile_lock'
remote:     from /app/tmp/buildpacks/b7af5642714be4eddaa5f35e2b4c36176b839b4abcd9bfe57ee71c358d71152b4fd2cf925c5b6e6816adee359c4f0f966b663a7f8649b0729509d510091abc07/lib/language_pack/instrument.rb:18:in `block (2 levels) in instrument'
remote:     from /app/tmp/buildpacks/b7af5642714be4eddaa5f35e2b4c36176b839b4abcd9bfe57ee71c358d71152b4fd2cf925c5b6e6816adee359c4f0f966b663a7f8649b0729509d510091abc07/lib/language_pack/instrument.rb:40:in `yield_with_block_depth'
remote:     from /app/tmp/buildpacks/b7af5642714be4eddaa5f35e2b4c36176b839b4abcd9bfe57ee71c358d71152b4fd2cf925c5b6e6816adee359c4f0f966b663a7f8649b0729509d510091abc07/lib/language_pack/instrument.rb:17:in `block in instrument'
remote:     from /app/tmp/buildpacks/b7af5642714be4eddaa5f35e2b4c36176b839b4abcd9bfe57ee71c358d71152b4fd2cf925c5b6e6816adee359c4f0f966b663a7f8649b0729509d510091abc07/vendor/ruby/heroku-18/lib/ruby/2.5.0/benchmark.rb:308:in `realtime'
remote:     from /app/tmp/buildpacks/b7af5642714be4eddaa5f35e2b4c36176b839b4abcd9bfe57ee71c358d71152b4fd2cf925c5b6e6816adee359c4f0f966b663a7f8649b0729509d510091abc07/lib/language_pack/instrument.rb:16:in `instrument'
remote:     from /app/tmp/buildpacks/b7af5642714be4eddaa5f35e2b4c36176b839b4abcd9bfe57ee71c358d71152b4fd2cf925c5b6e6816adee359c4f0f966b663a7f8649b0729509d510091abc07/lib/language_pack/helpers/bundler_wrapper.rb:86:in `instrument'
remote:  !     Push rejected, failed to compile Ruby app.
remote: 
remote:  !     Push failed
remote: Verifying deploy...
remote: 
remote: !   Push rejected to my-proyect-1234.
remote: 

It says 'remote: ! You must use Bundler 2 or greater with this lockfile.'

But my Bundler version is 2.0.0.pre.1

Don't know what to do, I tried uninstalling bundle and installing it again, I errased the Gemfile.lock and typing bundle again

Answer

Promise Preston picture Promise Preston · Jul 20, 2019

I had a similar experience.

Here's how I solved it

Display a list of all your local gems for the bundler gem

gem list bundler

N/B: The command above is for rbenv version manager, the one for rvm might be different

This will display the versions of the bundler gem installed locally

bundler (2.0.2, default: 1.17.2)

if you don't have bundler version 2 installed locally, then run

gem install bundler

OR

gem install bundler -v 2.0.2

if you have bundler version 2 already installed locally or just installed it, then you need to simply install an update for RubyGems Package Manager locally. To do this, run

gem update --system

And then finally run

bundle update --bundler

For Docker projects in Ruby on Rails

If you're experiencing this issue when trying to build your application using Docker, simply do this:

  1. Delete the Gemfile.lock file

  2. Please don't create it again by running bundle install.

  3. Run your docker build or docker-compose build command as appropriate to build your project.

This will re-create the Gemfile.lock file and setup the appropriate version of bundler necessary for your project in the Gemfile.lock file.

N/B: As a side note, you can also add this environment variable to your Dockerfile with the Bundler version defined.

ENV BUNDLER_VERSION=2.1.4

That's all.

I hope this helps.