127

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

Promise Preston
  • 24,334
  • 12
  • 145
  • 143
Pedro
  • 1,352
  • 2
  • 10
  • 22
  • 3
    If you're seeing this on a CI environment, set the BUNDLER_VERSION envvar to match your Gemfile.lock. `export BUNDLER_VERSION='2.0'` – DylanReile Apr 12 '19 at 22:21

20 Answers20

230

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.1.4, default: 1.17.2)

Note: Your versions might differ from the one here

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

gem install bundler

OR

gem install bundler -v 2.1.4

Note: Replace 2.1.4 with the version you want to install

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
halfer
  • 19,824
  • 17
  • 99
  • 186
Promise Preston
  • 24,334
  • 12
  • 145
  • 143
30

A bit late to the party but I just ran into this today as well, and this solution avoids having to uninstall Bundler: just run

heroku buildpacks:set https://github.com/bundler/heroku-buildpack-bundler2

as per discussion on the Bundler issue here.

Alex
  • 309
  • 2
  • 5
  • Just to clarify, if you already have `https://github.com/heroku/heroku-buildpack-ruby` in buildpacks, should you replace it with `https://github.com/bundler/heroku-buildpack-bundler2` or have it in addition to? – stevec Jan 26 '19 at 08:32
  • As far as I know there's no need to remove anything, with this command you're just telling Heroku that this is the buildpack you want to use for this app ([Heroku docs](https://devcenter.heroku.com/articles/buildpacks)). Also check out the rest of the discussion I linked to above and the warning [here](https://github.com/bundler/heroku-buildpack-bundler2) - this buildpack is not officially supported at the moment even though Bundler advises to use it in this [blog post](https://bundler.io/blog/2019/01/03/announcing-bundler-2.html). – Alex Jan 27 '19 at 09:43
  • I ended up using the `https://github.com/bundler/heroku-buildpack-bundler2` buildpack in place of `https://github.com/heroku/heroku-buildpack-ruby` and it seems to work. Thanks for the help – stevec Jan 27 '19 at 12:36
  • 4
    This buildpack has been deprecated and the Heroku `heroku/ruby` buildpack now supports bundler 2 directly – Schneems Feb 25 '19 at 19:13
  • What is Heroku? – IgorGanapolsky Dec 23 '20 at 16:15
27

I had same issue on Local Machine(Development) as-

You must use Bundler 2 or greater with this lockfile.
The issue was with gemfile.lock because my local bundle version and project bundle version was not matching! Here is solution-

  1. I deleted gemfile.lock
  2. Run the command - bundle install
    That solved my problem, it is smooth! Hope will work for others!
S.Yadav
  • 4,273
  • 3
  • 37
  • 44
  • 4
    A potential problem with this approach is that deleting Gemfile.lock causes all your version state to be lost. Bundler will compute new versions for all your gems, and given that there are going to be new versions of gems nearly every day, you'll get a tree of dependencies that's different from the one you've tested and commited to Gemfile.lock. That might break. – Dave Morse Dec 22 '20 at 19:09
8

simple gem update bundler did it for me.

ispirett
  • 648
  • 10
  • 10
6

I resolved this issue by running gem uninstall bundler to remove 2.0.0.pre.1, renamed the Gemfile.lock file (to remove it from use) and then ran bundle install to reinstall the gemfiles. In my case, I already had access to the earlier bundler version installed by heroku (so when I ran gem uninstall, I was shown all versions available and chose to remove 2.0.0.pre.1).

John Creamer
  • 9,704
  • 1
  • 14
  • 8
5

Even with bundler 2 on the system this error still happens when deploying an app with Ruby 2.6 since Ruby 2.6 ships with a default version of bundler.

If you are using Ruby 2.6 then upgrade to Ruby 2.6.1 to avoid this issue.

Sergey
  • 367
  • 4
  • 11
5

The Ruby 2.6.0 is not the case of this problem. The default version of Bundler incorrectly invoked when using bin stubs. For more details please refer the following link

Solution: Bundler 2 is available on the system and is the latest version, So it should be invoked instead of the default bundler version.

Update Rubygems

gem update --system

Update bundler

gem install bundler

Update Gemfile.lock in your project

bundler update --bundler
Jitendra Rathor
  • 607
  • 8
  • 11
4

Yup, so generally uninstalling your version of bundler, removing the gemfile.lock, and finally running gem install bundler -v 1.15.2(which is the version heroku is using) worked.

After that running git push heroku master worked!

Aleksander Jess
  • 161
  • 2
  • 14
2

For local system

gem install bundler:2.0.0.pre.1
bundle _2.0.0.pre.1_ install

Where "2.0.0.pre.1" is whatever version you need to bundle with.

Don't delete your Gemfile.lock for this, it's there for a reason.

Arye Eidelman
  • 1,579
  • 16
  • 22
2

If you're using a docker image like FROM:ruby:2.X.X then you can do the following:

FROM ruby:2.6.2
... # omitted
COPY Gemfile /myapp/Gemfile
COPY Gemfile.lock /myapp/Gemfile.lock
RUN gem uninstall bundler
RUN gem install bundler -v 2.1.4
RUN bundle update --bundler
RUN bundle install
... # omitted
Anthony
  • 15,435
  • 4
  • 39
  • 69
1

Heroku does not use Bundler 2.0, but 1.15.2, as the tracelog hints.

As far as I am aware, the "workaround" is to create your own buildpack, or simple fork their own:

Open lib/language_pack/ruby.rb in your editor, and change the following line:

BUNDLER_VERSION = "1.11.2"

(README.md at https://github.com/heroku/heroku-buildpack-ruby)

Update: As of Ruby 2.6.1 and Bundler 2.0.1, Heroku now does support Bundler 2.0.1. https://devcenter.heroku.com/articles/bundler-version#known-upgrade-issues

This is not the case for Ruby 2.6.0, as this is incorrectly invoked from binstubs, as @Schneems has mentioned in the comment. He has kindly reported this as a Ruby Bug #15622

Community
  • 1
  • 1
Frederik Spang
  • 3,379
  • 1
  • 25
  • 43
  • We now support Bundler 2.0.1. Also FWIW changing the bundler version doesn't do anything, you also have to build and host that version of bundler on our S3 repo. – Schneems Feb 25 '19 at 19:13
  • @Schneems Updated the answer with reference to heroku devcenter, and your bug in the Ruby tracker! Thanks for the update; Didn't see this myself until now! – Frederik Spang Feb 25 '19 at 23:34
1

For people who are not using Heroku:

I Tried everything and I was still receiving this error. even this link didn't help me: https://github.com/jekyll/jekyll/issues/7463

So this was my solution:

Push your code on GitHub. delete project folder create a new folder and pull your code bundle install That's it. bundler update --bundler was not helping me at the end and I didn't use it.

One more important thing: I updated my ruby version but I was getting this error because my RVM default version was an old version. even when you use rvm use VERSION_NUMBER -- default will not help because as soon as you log out from terminal the default version will change to the old one and you will have the same issue.

For this you can use this answer: How to set default Ruby version with RVM?

or just uninstall old ruby version with rvm uninstall X.X.X and install the new one with rvm install X.X.X and make it default by rvm use --default X.X.X.

cheers.

Navid Farjad
  • 435
  • 5
  • 16
1

I got the same problem for Ruby 2.6.3, nothing listed in answers could help. The only the following solution worked for me:

  1. bundle update rails

  2. Remove Gemfile.lock

  3. bundle

Dharman
  • 30,962
  • 25
  • 85
  • 135
Timo Moss
  • 83
  • 1
  • 8
1

I had the same issue. In my Gemfile.lock i saw at the end "bundled with bundler 2.0.2", but running bundle --version gave me version 1.17... For me it solved just updateing my bundler with the following command: bundle update --bundler see bundler documentation

dcts
  • 1,479
  • 15
  • 34
0

I deleted the project and made a git clone from the Heroku app, don´t know if it is a good solution, but it worked for me.

Pedro
  • 1,352
  • 2
  • 10
  • 22
0

I got the same issue in my local system, my ruby version was low due to which the error was occurring. Fixed it by switching it to updated versions of ruby.

Dyaniyal Wilson
  • 1,012
  • 10
  • 14
0

Using bundler 2.0.1 allows for automatic version switching as required by the lock file. In this regard, installing bundler 2.0.1 worked for me.
Installing bundler 2.0.1
gem install bundler -v 2.0.1
Update bundler
bundle update -bundler

0

I had the same problem today.

In my case the problem was caused by using rvm gemset other than latest I have with ruby 2.7.1 and bundler 2.1.4 (same bundle Gemfile was locked with).

So just take a look at your rvm environment before doing any other solution listed here. Specially if you're running your project on production.

Happy hacks !

luilver
  • 33
  • 6
0

Delete gem history and modules installed in rails application.

$ rm -rf vendor/bundle
$ rm Gemfile.lock

and, bundle

$ bundle install --path=vendor/bundle

and, start Rails Server

$ bundle exec rails s

and, connect to browser.

http://localhost:3000/

jojo
  • 569
  • 7
  • 7
0

Same error, but locally. I finally figured out I was using wrong version of ruby on my command line (I'm using uru to manage ruby versions.) After all, how could the gemfile use and produce a lock file with version 2.1.4, yet my search didn't find that version!

>gem list bundler

*** LOCAL GEMS ***

bundler (default: 1.16.2, 1.13.1)
capistrano-bundler (1.6.0, 1.1.4)

So I changed to the correct version of ruby and all was good.

Remember, gems are stored with your Ruby version!

dirktay
  • 55
  • 4