Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 618
Dave Slutzkin Avatar asked Jan 10 '19 07:01

Dave Slutzkin


People also ask

How do I upgrade to bundler 2?

Installing Bundler 2 The first step in upgrading to Bundler 2 is installing the Bundler 2 gem. To install it the usual way, run gem install bundler and RubyGems will install the latest version of Bundler.

How can I remove default version of bundler?

You have to delete the . gemspec file corresponding to the default gem you want to delete. So first, locate where those files are. Delete the one you don't need.


1 Answers

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.

like image 50
tmatilai Avatar answered Oct 20 '22 01:10

tmatilai