19

I'm new to rbenv (was using RVM for long time). Today I do clean uninstall of my RVM and install rbenv. I managed to install Ruby 2.5.1 without any issues.

But when I try to run bundle install for a project today, I got the following error:

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

Seems like something is broken with my bundler installation but I'm not sure what is wrong. Running gem install bundler with sudo doesn't solve the problem.

Here is the full trace:

$ echo $SHELL
/bin/zsh


$ cat ~/.gemrc
gem: --no-document
install: --no-document
update: --no-document


$ rbenv versions
  system
* 2.5.1 (set by /Users/zulh/.rbenv/version)


$ ruby -v
ruby 2.5.1p57 (2018-03-29 revision 63029) [x86_64-darwin16]


$ which ruby
/Users/zulh/.rbenv/shims/ruby


$ gem env
RubyGems Environment:
  - RUBYGEMS VERSION: 2.7.6
  - RUBY VERSION: 2.5.1 (2018-03-29 patchlevel 57) [x86_64-darwin16]
  - INSTALLATION DIRECTORY: /Users/zulh/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0
  - USER INSTALLATION DIRECTORY: /Users/zulh/.gem/ruby/2.5.0
  - RUBY EXECUTABLE: /Users/zulh/.rbenv/versions/2.5.1/bin/ruby
  - EXECUTABLE DIRECTORY: /Users/zulh/.rbenv/versions/2.5.1/bin
  - SPEC CACHE DIRECTORY: /Users/zulh/.gem/specs
  - SYSTEM CONFIGURATION DIRECTORY: /Users/zulh/.rbenv/versions/2.5.1/etc
  - RUBYGEMS PLATFORMS:
    - ruby
    - x86_64-darwin-16
  - GEM PATHS:
     - /Users/zulh/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0
     - /Users/zulh/.gem/ruby/2.5.0
  - GEM CONFIGURATION:
     - :update_sources => true
     - :verbose => true
     - :backtrace => false
     - :bulk_threshold => 1000
     - "gem" => "--no-document"
     - "install" => "--no-document"
     - "update" => "--no-document"
  - REMOTE SOURCES:
     - https://rubygems.org/
  - SHELL PATH:
     - /Users/zulh/.rbenv/versions/2.5.1/bin
     - /usr/local/Cellar/rbenv/1.1.1/libexec
     - /Users/zulh/.rbenv/shims
     - /usr/local/bin
     - /Users/zulh/go/bin
     - /usr/local/bin
     - /Users/zulh/go/bin
     - /Users/zulh/.rbenv/shims
     - /usr/local/bin
     - /Users/zulh/go/bin
     - /Users/zulh/.rbenv/shims
     - /usr/local/bin
     - /Users/zulh/go/bin
     - /usr/local/bin
     - /usr/bin
     - /bin
     - /usr/sbin
     - /sbin
     - /Library/Frameworks/Mono.framework/Versions/Current/Commands
     - /Applications/Postgres.app/Contents/Versions/latest/bin
     - /Users/zulh/projects/tifig/build/tifig
     - /Applications/Postgres.app/Contents/Versions/latest/bin
     - /Users/zulh/projects/tifig/build/tifig
     - /Applications/Postgres.app/Contents/Versions/latest/bin
     - /Users/zulh/projects/tifig/build/tifig
     - /Applications/Postgres.app/Contents/Versions/latest/bin
     - /Users/zulh/projects/tifig/build/tifig
     - /Applications/Postgres.app/Contents/Versions/latest/bin


$ which bundler
/Users/zulh/.rbenv/shims/bundler


$ bundler --version
Traceback (most recent call last):
    2: from /Users/zulh/.rbenv/versions/2.5.1/bin/bundler:23:in `<main>'
    1: from /Users/zulh/.rbenv/versions/2.5.1/lib/ruby/2.5.0/rubygems.rb:308:in `activate_bin_path'
/Users/zulh/.rbenv/versions/2.5.1/lib/ruby/2.5.0/rubygems.rb:289:in `find_spec_for_exe': can't find gem bundler (>= 0.a) with executable bundler (Gem::GemNotFoundException)


$ cd projects/www.ruby-lang.org


$ bundle install --without production
Traceback (most recent call last):
    2: from /Users/zulh/.rbenv/versions/2.5.1/bin/bundle:23:in `<main>'
    1: from /Users/zulh/.rbenv/versions/2.5.1/lib/ruby/2.5.0/rubygems.rb:308:in `activate_bin_path'
/Users/zulh/.rbenv/versions/2.5.1/lib/ruby/2.5.0/rubygems.rb:289:in `find_spec_for_exe': can't find gem bundler (>= 0.a) with executable bundle (Gem::GemNotFoundException)


$ sudo gem install bundler
Password:
Successfully installed bundler-2.0.1
1 gem installed


$ which bundler
/Users/zulh/.rbenv/shims/bundler


$ bundler --version
Traceback (most recent call last):
    2: from /Users/zulh/.rbenv/versions/2.5.1/bin/bundler:23:in `<main>'
    1: from /Users/zulh/.rbenv/versions/2.5.1/lib/ruby/2.5.0/rubygems.rb:308:in `activate_bin_path'
/Users/zulh/.rbenv/versions/2.5.1/lib/ruby/2.5.0/rubygems.rb:289:in `find_spec_for_exe': can't find gem bundler (>= 0.a) with executable bundler (Gem::GemNotFoundException)


$ bundle install --without production
Traceback (most recent call last):
    2: from /Users/zulh/.rbenv/versions/2.5.1/bin/bundle:23:in `<main>'
    1: from /Users/zulh/.rbenv/versions/2.5.1/lib/ruby/2.5.0/rubygems.rb:308:in `activate_bin_path'
/Users/zulh/.rbenv/versions/2.5.1/lib/ruby/2.5.0/rubygems.rb:289:in `find_spec_for_exe': can't find gem bundler (>= 0.a) with executable bundle (Gem::GemNotFoundException)

How to fix this issue?

Note: I'm using OSX 10.12.6

Zulhilmi Zainudin
  • 9,017
  • 12
  • 62
  • 98
  • Possible duplicate of [find\_spec\_for\_exe': can't find gem bundler (>= 0.a) (Gem::GemNotFoundException)](https://stackoverflow.com/questions/47026174/find-spec-for-exe-cant-find-gem-bundler-0-a-gemgemnotfoundexception) – anothermh Jan 05 '19 at 00:01

7 Answers7

66

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
stefansundin
  • 2,826
  • 1
  • 20
  • 28
mznet07
  • 903
  • 6
  • 13
  • 7
    To clarify, those 1-2-3 are *options* (1, 2, OR 3) — I only did #2 and it worked. Thanks! – Whatcould Feb 05 '19 at 19:40
  • 1
    @IgorGanapolsky rbenv is a ruby version manager and you need to install it manually. you can easily install it throught brew or scripts. Fyi, refer to its document(https://github.com/rbenv/rbenv#installation) – mznet07 Dec 24 '20 at 00:32
7

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...

Danin
  • 71
  • 3
  • 2
    Made an account to post this and everything, so I really hope it helps. – Danin Jan 05 '19 at 01:20
  • 1
    Note: Definitely not a duplicate of the other-mentioned question - completely different error message, as indicated bold above - with a completely different implication of malfunction and eventual resolution. (I think. Not trying to step on toes!) – Danin Jan 05 '19 at 02:11
6

This is how I finally solved this problem:

$ cd /path/to/my/project/
$ gem install bundler -v 1.17.3
$ bundle install
Zulhilmi Zainudin
  • 9,017
  • 12
  • 62
  • 98
5

Sometimes just running bundle update --bundler in the project directory is enough.

Dave Wood
  • 13,143
  • 2
  • 59
  • 67
2

I am using rbenv 1.1.1 and ruby 2.5.1 and got the same error while running bundle install. gem update --system solved the problem

Lana Dz
  • 71
  • 6
2

I removed my Gemfile.lock and it worked fine after that.

Ian Turton
  • 10,018
  • 1
  • 28
  • 47
0

Find out which bundler version you should use:

$ grep -A 1 "BUNDLED WITH" Gemfile.lock | tail -n 1

and install that version:

$ gem install bundler -v  <replace with version>

Or you can just run:

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