27

I'm a Rails newb who's trying out Rails on a DigitalOcean droplet. The installations seemed to work fine, but I'm getting a curious error message when I try to generate a scaffold:

DO 10:48 Rails/simple (master) → rails generate scaffold User name:string email:string
Traceback (most recent call last):
        5: from bin/rails:3:in `<main>'
        4: from bin/rails:3:in `load'
        3: from /home/tony/rails/simple/bin/spring:10:in `<top (required)>'
        2: from /home/tony/rails/simple/bin/spring:10:in `new'
        1: from /home/tony/.rvm/rubies/ruby-2.6.0/lib/ruby/2.6.0/bundler/lockfile_parser.rb:95:in `initialize'
/home/tony/.rvm/rubies/ruby-2.6.0/lib/ruby/2.6.0/bundler/lockfile_parser.rb:108:in `warn_for_outdated_bundler_version': You must use Bundler 2 or greater with this lockfile. (Bundler::LockfileError)
DO 10:49 Rails/simple (master) → bundle list bundler
/home/tony/.rvm/gems/ruby-2.6.0/gems/bundler-2.0.1
DO 10:50 Rails/simple (master) → gem list bundler

*** LOCAL GEMS ***

bundler (2.0.1, default: 1.17.2)
bundler-unload (1.0.2)
rubygems-bundler (1.4.5)

I.e., the current Bundler gem is version 2.0.1, but Rails still thinks it's insufficient.

I can't find anything similar on the web. The only red flag I can see is that the bundler gem shows a default version of 1.17.2. How do I begin to diagnose the problem?

Tony
  • 1,221
  • 2
  • 12
  • 25
  • 2
    I'm in the same exact boat! – Todd German Jan 06 '19 at 17:17
  • 3
    I ran into the same problem. I downgraded with `gem uninstall bundler`, followed by `gem install bundler -v 1.17.3` to revert back to the last pre 2 version. I saw this across 3 separate systems using different version managers (ASDF, rbenv, rvm) which led me to believe it wasn't ready for production use yet. You might look here: https://bundler.io/blog/2019/01/04/an-update-on-the-bundler-2-release.html try installing 1.17.2 maybe? – Jay Dorsey Jan 06 '19 at 19:14
  • 1
    @JayDorsey: That worked. Thanks! If you post it as an answer, I'll accept and upvote it. – Tony Jan 07 '19 at 02:36
  • Done. I'm glad it worked! – Jay Dorsey Jan 07 '19 at 02:46

6 Answers6

26

This helped me: gem update --system

22

I ran into the same issue & resolved it by downgrading with gem uninstall bundler, followed by gem install bundler -v 1.17.3 to revert back to the last pre 2 version.

I saw this across 3 separate systems using different version managers (ASDF, rbenv, rvm) and this resolved the issue.

There is some information on getting both versions to play nicely here. The root cause of this issue may have been a bug (which appears to have since been fixed)

Per the comment from @MatijsvanZuijlen below, and the bundler documentation, you should also be able to specify which version of bundler you want to use at runtime with bundle _1.17.3_ install

Jay Dorsey
  • 3,563
  • 2
  • 18
  • 24
  • THANK YOU. This, plus setting the Bundler version to 1.17.3 in the Gemfile.lock, resolved this. (removing the .lock file and rerunning bundle didn't address that, but perhaps I was doing something wrong.) – mungojerie Jan 17 '19 at 21:17
  • Thanks guys!!! I had the same problem... downgrading to bundle 1.17.3, removing the lock file and rerunning the bundle install worked for me... :) – Alon Samuel Jan 27 '19 at 01:15
  • 2
    You don't have to remove bundler 2.0: You can also force running version 1.17.3 by running `bundle _1.17.3_`. – Matijs van Zuijlen Feb 10 '19 at 14:58
  • @MatijsvanZuijlen I had an opportunity to test that today and it doesn't seem to work (at least on my system). I have both 1.17.3 and 2.0.1 via `gem install`, 1.17.3 specified. Even though `gem list bundler` shows both versions, I get an error `Could not find 'bundler' (= 1.17.3) - did find: [bundler-2.0.1,bundler-1.7.3] (Gem::LoadError)` which is kind of odd since it seems to indicate it _can_ find 1.17.3. Hopefully this might work for others though – Jay Dorsey Feb 12 '19 at 18:50
  • 1
    @JayDorsey it looks like you don't have `1.17.3`, but you do have `1.7.3` (note the minor version 17 vs 7). – Matijs van Zuijlen Feb 13 '19 at 20:37
  • @MatijsvanZuijlen that's a good catch, let me make sure that wasn't a typo! – Jay Dorsey Feb 13 '19 at 21:49
  • @MatijsvanZuijlen You are correct. It does work now, it wasn't a typo, I had the wrong version installed. I must have accidentally installed 1.7.3 at some point and after the 2.0 upgrade things just broke. I know the new version was supposed to also auto-switch for you under certain conditions, I just assumed it was broken :/ – Jay Dorsey Feb 13 '19 at 21:54
5

This is my solution:

  1. (if you have an old version of Bundler), run the command:

    bundle update --bundler

  2. Run the command:

    gem update --system

  3. run the rake

    rake db:migrate

mnille
  • 1,328
  • 4
  • 16
  • 20
JHero23
  • 149
  • 3
  • 10
4

After you try any of the solutions above, restart your terminal window.

I was stuck with my terminal showing 2 versions of bundler even when i uninstalled the old version until i killed terminal and opened a new window.

ricks
  • 3,154
  • 31
  • 51
  • 1
    I spent a lot of time trying every other answer to this question; but this was the only thing that worked. – piersb Feb 13 '20 at 16:39
2

I got issue after updating ruby version(2.4.6) as-

You must use Bundler 2 or greater with this lockfile.

Here is how I resolved it-
When i checked bundler version bundler -v

$ Bundler version 1.16.1  

I updated bundlere version using-

$ gem install bundler -v 2.0.1

And got issue resolved!

S.Yadav
  • 4,273
  • 3
  • 37
  • 44
-1

Here is how I resolve it:

delete ruby and install Ruby 2.6.7 via source code, and soft link to /usr/bin/

wget https://cache.ruby-lang.org/pub/ruby/2.6/ruby-2.6.7.tar.gz
tar xvf ruby-2.6.7.tar.gz
./configure 
make -j32 && sudo make install
sudo ln -sf /usr/local/bin/ruby /usr/bin/ruby

then, run:

bundle install

then, run:

sudo bundle exec jekyll serve

It works for me.

Liu Shi
  • 1
  • 1