100

I'm executing the following script:

gem install rdoc --no-document
gem install bundle
bundle

output:

+ gem install rdoc --no-document
Successfully installed rdoc-6.1.1
1 gem installed
+ gem install bundle
Successfully installed bundle-0.0.1
Parsing documentation for bundle-0.0.1
Done installing documentation for bundle after 2 seconds
1 gem installed
1 gem installed
+ bundle install
/usr/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)
    from /usr/lib/ruby/2.5.0/rubygems.rb:308:in `activate_bin_path'
    from /srv/myuser/.gem/ruby/2.5.0/bin/bundle:23:in `<main>'

I've added /srv/myuser/.gem/ruby/2.5.0/bin to my path so I was able to install gems.

the gem env shows

RubyGems Environment:
  - RUBYGEMS VERSION: 2.7.7
  - RUBY VERSION: 2.5.1 (2018-03-29 patchlevel 57) [x86_64-linux]
  - INSTALLATION DIRECTORY: /usr/lib/ruby/gems/2.5.0
  - USER INSTALLATION DIRECTORY: /srv/myuser/.gem/ruby/2.5.0
  - RUBY EXECUTABLE: /usr/bin/ruby
  - EXECUTABLE DIRECTORY: /usr/bin
  - SPEC CACHE DIRECTORY: /srv/myuser/.gem/specs
  - SYSTEM CONFIGURATION DIRECTORY: /etc
  - RUBYGEMS PLATFORMS:
    - ruby
    - x86_64-linux
  - GEM PATHS:
     - /usr/lib/ruby/gems/2.5.0
     - /srv/myuser/.gem/ruby/2.5.0
  - GEM CONFIGURATION:
     - :update_sources => true
     - :verbose => true
     - :backtrace => false
     - :bulk_threshold => 1000
     - "gem" => "--user-install"
  - REMOTE SOURCES:
     - https://rubygems.org/
  - SHELL PATH:
     - /usr/local/sbin
     - /usr/local/bin
     - /usr/bin

gem list shows the installed gems. I can also find bundle when I perform:

ls -ltrah /srv/myuser/.gem/ruby/2.5.0/bin

I've also tried to install bundler but that didn't also help. What am I doing wrong?

gem which bundle is showing nothing.gem spec bundle is showing it.

Update: I tried to install bundler before running bundle but the same issue appears while:

gem list bundle shows

bundle (0.0.1)
bundler (2.0.1)
Promise Preston
  • 24,334
  • 12
  • 145
  • 143
DenCowboy
  • 13,884
  • 38
  • 114
  • 210

12 Answers12

169

Bundler version 2 introduced a new feature to automatically use the version of Bundler specified in the Gemfile.lock of your project. Thus, if you have an existing Gemfile.lock with a line like this at the bottom

BUNDLED WITH
   1.17.3

Bundler will try to run with a Bundler version < 2.0. Since you just have Bundler 2.0.1 (and Rubygems >= 2.7.0) installed, this fails with this rather unhelpful error message.

To fix this, you could

  • remove the lines from your Gemfile.lock and to use bundler 2.x everywhere from now on, or
  • install a bundler 1.x version with gem install bundler -v '< 2.0' to use the appropriate version as specified by your Gemfile.lock.

More information about this can be found on the Bundler blog.

Holger Just
  • 52,918
  • 14
  • 115
  • 123
  • 6
    IMO This should be the correct answer. Another option to add to this list of possible fixes is to delete `Gemfile.lock` and run bundle install again – Americo Savinon Jul 03 '19 at 15:18
  • Thanks for this answer, saved me a lot of trying. – Orlando Aug 01 '19 at 15:27
  • If one updates `rubygems` to newer version - it should solve the problem as well. `gem update --system` to upgrade to latest version ( or at least `gem update --system '2.7.10' to stay on 2.7.x version of RubyGems`. – Alexej Kubarev Jan 10 '20 at 00:51
  • The Bundler blog provides an one-line command to install the exact version of Bundler that RubyGems is looking for: ```shell gem install bundler -v "$(grep -A 1 "BUNDLED WITH" Gemfile.lock | tail -n 1)" ``` You can read [their article](https://bundler.io/blog/2019/05/14/solutions-for-cant-find-gem-bundler-with-executable-bundle.html) for more information. – Tom Nguyen Nov 13 '20 at 11:40
95

As per the description mentioned in the post , before running the below mentioned command:

bundle install

in the script, you need to run the below command:

gem install bundler

So, the sequence of commands to work would be:

gem install bundler
bundle install

Update the bundler command if if does not work to:

 gem install bundler -v '1.17.3'

Reason for the break in functionalities in bundler 2.0 is given in below mentioned link:

https://bundler.io/blog/2019/01/04/an-update-on-the-bundler-2-release.html

Rohan
  • 2,681
  • 1
  • 12
  • 18
48

I couldn’t even do bundle -v. This sorted it out:

gem update --system

Got the info from here (similar problem): find_spec_for_exe': can't find gem bundler (>= 0.a) (Gem::GemNotFoundException)

Probably some version mismatch between ruby + gem + bundler

estani
  • 24,254
  • 2
  • 93
  • 76
  • 1
    This solved the issue for me and also [matches bundler's own docs](https://bundler.io/blog/2019/05/14/solutions-for-cant-find-gem-bundler-with-executable-bundle.html) – Josh Feb 27 '20 at 21:46
19
gem install bundler -v '< 2.0' 
Matthias
  • 4,481
  • 12
  • 45
  • 84
rusllonrails
  • 5,586
  • 3
  • 34
  • 27
8

I faced this same issue. The issue is caused by the fact that RubyGems cannot find an executable bundle for the bundler gem on the system

To fix it, first run

gem install bundler

if you don't have bundler gem installed locally, then run

gem update --system

That's all

I hope this helps

Promise Preston
  • 24,334
  • 12
  • 145
  • 143
  • I solved it with answer, which is also on this site: https://bundler.io/blog/2019/05/14/solutions-for-cant-find-gem-bundler-with-executable-bundle.html – DiegoG Sep 10 '19 at 22:30
  • `gem update --system -N` if stuck on installing documents to skip it – Marco Mar 02 '22 at 15:47
4

I had the same problem recently. In my case I have installed a version on bundler different from what is logged in the Gemfile.lock. Please check

Dende
  • 545
  • 6
  • 19
4

This may help solve the problem

bundle update --bundler
Abdul Basit
  • 131
  • 1
  • 4
3

You've to install the exact version of Bundler that RubyGems is looking for by running:

$ gem install bundler -v "$(grep -A 1 "BUNDLED WITH" Gemfile.lock | tail -n 1)"
Manuel Schmitzberger
  • 5,162
  • 3
  • 36
  • 45
1

I just faced the same error today. The bundler version which I had installed in my system previously was: 1.16.6

Followed the instructions in the official bundler docs on How to Upgrade to Bundler 2 and the below two steps did the trick:

  1. gem install bundler (Helps you get the latest version of bundler which as of today is 2.0.2)
  2. bundle update --bundler
boddhisattva
  • 6,908
  • 11
  • 48
  • 72
1

I saw a similar error message for the travis bundle after upgrading mac os to Catalina.

Traceback (most recent call last):
    2: from /usr/local/bin/travis:22:in `<main>'
    1: from /usr/local/Cellar/ruby/2.6.5/lib/ruby/2.6.0/rubygems.rb:263:in `bin_path'
/usr/local/Cellar/ruby/2.6.5/lib/ruby/2.6.0/rubygems.rb:284:in `find_spec_for_exe': can't find gem travis (>= 0.a) with executable travis (Gem::GemNotFoundException)

To resolve the issue, I reinstalled travis from source.

brew remove travis;
brew install -s travis
1

YEP, this works:

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

From: https://bundler.io/blog/2019/05/14/solutions-for-cant-find-gem-bundler-with-executable-bundle.html

kingPuppy
  • 2,937
  • 1
  • 18
  • 18
0

Perhaps an over-specific (and nooby) answer:

In RubyMine my project was set to Ruby 3.0.0 However, my terminal was using 2.7.6

I used RVM rvm use 3.0.0 to set my terminal to 3.0.0 Problem solved

Jake
  • 4,322
  • 6
  • 39
  • 83