Rails logo

Rails: Solution for "can't find gem bundler (>= 0.a) with executable bundle"



So you have cloned a fresh copy of your old rails project or you are trying to replicate someone else's project which used to work previously just fine, and now after you have installed the correct ruby and rails versions you are bombarded with this error when you try to bundle install:
Can't find gem bundler (>= 0.a) with executable bundle (Gem::GemNotFoundException)

What is this error?

Well, the error is basically saying that RubyGems was unable to find the exact version of bundler that is in your Gemfile.lock!
Some versions of RubyGems try to use the exact version of Bundler listed in your Gemfile.lock anytime you run the bundle command. If you are using one of those versions of RubyGems but your bundler version installed is different than the one listed in the Gemfile.lock, you will run into this error.

Solution

There are number of solutions to this, but the most recommended solutions are these two:

Install the exact bundler version

This is because the version of bundler that is 100% guaranteed to work with a given Gemfile.lock is the bundler version that generated it. To do so, you can run the following command:

$ gem install bundler -v "$(grep -A 1 "BUNDLED WITH" Gemfile.lock | tail -n 1)"

Update RubyGems

More recent RubyGems versions are less strict and as long as the major bundler version in the BUNDLED WITH section of your Gemfile.lock matches the major of bundler version you are running, it won't generate an error. You can do that by running the following command:

$ gem update --system



Done


Leave a comment


Post


Comments

Be the first one to leave a comment!