Search code examples
ruby-on-railsrubybundlerruby-2.6

Mismatched bundler version - bundler 2, ruby 2.6


We've just updated ruby to 2.6 and bundler to 2. Now we're getting:

# bin/rails console
You must use Bundler 2 or greater with this lockfile.

This was previously happening with bundle exec:

# bundle exec rails console
You must use Bundler 2 or greater with this lockfile.

At that point we were still running 1.17.2 by default:

# gem list bundler

*** LOCAL GEMS ***

bundler (2.0.1, default: 1.17.2)

So we ran gem uninstall bundler --version 1.17.2 and then bundle exec started working.

But the bin stubs like bin/rails are still failing.

How can it be running 1.17.2 when that's been uninstalled?


Solution

  • The diagnose in your answer seems right. But it seems you can activate the latest installed Bundler gem (installed by gem install bundler) by adding this before the require 'bundler/setup' line:

    Gem::Specification.find_by_name('bundler').activate
    

    More specific version requirements can also be used if needed. For example:

    Gem::Specification.find_by_name('bundler', '~> 2.0.1').activate
    

    find_by_name throws LoadError derived exception if the gem is not found.