rbenv — 'find_spec_for_exe': can't find gem bundler (>= 0.a) with executable bundle (Gem::GemNotFoundException)

bundler was updated from 1.7 to 2 on Jan 4. Due to the update, gem install bundler will install version 2 since Jan 4, if you trying to install bundler without specifying a version. And bundler 2.0 requires rubygems version at least 3.0.

First, check your rubygems installed on your local machine, using gem --version. If you use ruby v2.5.1, your rubygems version will be or 2.7.x and under 3.x.

RubyGems Environment:
    - RUBYGEMS VERSION: 2.7.6
    - RUBY VERSION: 2.5.1 (2018-03-29 patchlevel 57) [x86_64-darwin17]

Under rubygems version 3.x, gem install bundler command will not work well.

To fix problem,

1) update rubygems

gem update --system

2) install an older version of bundler

gem install bundler -v 1.17.3

3) install Ruby 2.6. 2.6 was released on last Christmas, Ruby 2.6 merges bundler gem and use rubygems 3.0.1 as default. Since Ruby 2.6, you don't need to install bundler manually.

rbenv install 2.6

Just wanted to mention, I found this just today while searching for it - and fixed it myself. Here's the key;

can't find gem bundler (>= 0.a) with executable bundle (Gem::GemNotFoundException)

I know nothing about any of this, I'm a hacker who gets lucky - I noticed there's a bin/bundle executable in the checked-out git repo I'm trying to work with, and tried to run it directly out of sheer desperation. The message above implied (to me) that something's executable wasn't working, not that it wasn't present (as some searches lacked the noted text, and simply couldn't find the thing) so....anyways.

[rndusr@monster live]$ bin/bundle
Traceback (most recent call last):
    2: from bin/bundle:3:in `<main>'
    1: from /home/rndusr/.rbenv/versions/2.5.3/lib/ruby/2.5.0/rubygems.rb:263:in `bin_path'
/home/rndusr/.rbenv/versions/2.5.3/lib/ruby/2.5.0/rubygems.rb:289:in `find_spec_for_exe': Could not find 'bundler' (1.16.6) required by your /usr/src/git/redacted/live/Gemfile.lock. (Gem::GemNotFoundException)
To update to the lastest version installed on your system, run `bundle update --bundler`.
To install the missing version, run `gem install bundler:1.16.6`

Hey finally an error message that helps!

Thus, I ran gem install bundler:1.16.6 and re-ran the original command, and to my great (and hard-earned) joy, it finally worked.

I'm not 100% sure that fits as 'an answer' - don't just blindly run the command I came to, but rather consider to repeat the process to potentially reveal which issue you're having. Good luck!

EDIT for further backing: While being led to this conclusion, I also found that the bundle command would fail wholesale - but only in the project directory - which further implied that it was something 100% project-related. I don't know what bundle is or how it works internally, but by this behavior I figured it was sub-loading scripts/executables within the git repo (similar to how git's commands can be contextual to working dirs) so filestructure examination was next. That's when the bin folder was discovered, with an executable named bundle - which comes full circle to above.

FWIW - someone who knows more than me regarding bundle (I don't understand it well enough to know who to report it to, or even if this is abnormal behavior) should potentially file an issue with their github indicating that it's silently masking plaintext error messages they created to guide a user to a proper solution. Personally I'd have bin/bundle throw an exit code indicating useful output coming to stderr and pipe it on through...


This is how I finally solved this problem:

$ cd /path/to/my/project/
$ gem install bundler -v 1.17.3
$ bundle install