Alvaro
Alvaro

Reputation: 41605

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

I used sudo bundle install and that might be the cause of the issue?

Now I have:

I'm getting the following error when trying to run bundle exec jekyll serve or just jekyll serve

/Users/myusername/.rvm/rubies/ruby-2.3.5/lib/ruby/site_ruby/2.3.0/rubygems.rb:271:in `find_spec_for_exe': can't find gem bundler (>= 0.a) (Gem::GemNotFoundException)
    from /Users/myusername/.rvm/rubies/ruby-2.3.5/lib/ruby/site_ruby/2.3.0/rubygems.rb:299:in `activate_bin_path'
    from /Users/myusername/.rvm/gems/ruby-2.3.5/bin/bundle:23:in `<main>'
    from /Users/myusername/.rvm/gems/ruby-2.3.5/bin/ruby_executable_hooks:15:in `eval'
    from /Users/myusername/.rvm/gems/ruby-2.3.5/bin/ruby_executable_hooks:15:in `<MacBooMacBook-MacBook-MacBook-Pro-MacBook-PrMacBook-MacBooMacBMaMacBMaMaMaMaMaMaMaMaMacBMaMaMaMacBMa

Also, when accessing the folder in which I have my blog cd my_path I get the following message:

VM used your Gemfile for selecting Ruby, it is all fine - Heroku does that too, you can ignore these warnings with 'rvm rvmrc warning ignore /Library/WebServer/Documents/blog/Gemfile'. To ignore the warning for all files run 'rvm rvmrc warning ignore allGemfiles'. Unknown ruby interpreter version (do not know how to handle): RUBY_VERSION.

I've no idea how to solve this. I just want to create my static blog and honestly I have no idea about Ruby, Gem or Bundle :) So I would appreciate some insights!

Upvotes: 280

Views: 210003

Answers (18)

Jo&#227;o Rocha
Jo&#227;o Rocha

Reputation: 755

This fixed it:

  1. Remove Gemfile.lock rm Gemfile.lock
  2. run bundle install again

EDIT: DON'T DO IT IN PRODUCTION!

For production go to this answer.

Upvotes: 63

mansoor.khan
mansoor.khan

Reputation: 2616

I spent a lot of time on this as well. I was getting the same error on running rails server. After countless hours, I found out that inside the .bundle/config file, the bundle path was set as: BUNDLE_PATH: "vendor/bundle". I removed it and ran bundle install again. It installed the gems in the $HOME/.rvm/gems/ruby-* folder and then rails s ran successfully.

Just adding my solution here in case anyone else is stuck in a similar situation without any luck.

Upvotes: 0

Anshuman Bisoyi
Anshuman Bisoyi

Reputation: 236

export PATH="$HOME/.rbenv/bin:$PATH" eval "$(rbenv init -)"

Upvotes: 1

stevec
stevec

Reputation: 52777

I was getting this error when running bin/dev

bin/dev
/Users/st/.rbenv/versions/3.0.3/lib/ruby/site_ruby/3.0.0/rubygems.rb:265:in `find_spec_for_exe': can't find gem foreman (>= 0.a) with executable foreman (Gem::GemNotFoundException)
    from /Users/st/.rbenv/versions/3.0.3/lib/ruby/site_ruby/3.0.0/rubygems.rb:284:in `activate_bin_path'
    from /Users/st/.rbenv/versions/3.0.3/bin/foreman:25:in `<main>'

I tried a bunch of things, but what fixed it was simply:

gem install foreman

And now bin/dev works as expected again.

Upvotes: -2

Naser Mirzaei
Naser Mirzaei

Reputation: 822

to install bundler that matches with your Gemfile.lock use:

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

Upvotes: 18

user208769
user208769

Reputation: 2226

Adding to the many answers, my problem stemmed from wanting to use the docker's ruby as a base, but then using rbenv on top. This screws up a lot of things.

I fixed it in this case by:

  • The Gemfile.lock version did need updating - changing the "BUNDLED WITH" to the latest version did at one point change the error message, so may have been required
  • in .bash_profile or .bashrc, unsetting the environment variables:
unset GEM_HOME
unset BUNDLE_PATH

After that, rbenv worked fine. Not sure how those env vars were getting loaded in the first place...

Upvotes: 5

Rahul Dess
Rahul Dess

Reputation: 2597

In my case the above suggestions did not work for me. Mine was little different scenario.

When i tried installing bundler using gem install bundler .. But i was getting

ERROR:  While executing gem ... (Gem::FilePermissionError)
    You don't have write permissions for the /Library/Ruby/Gems/2.3.0 directory.

then i tried using sudo gem install bundler then i was getting

ERROR:  While executing gem ... (Gem::FilePermissionError)
  You don't have write permissions for the /usr/bin directory.

then i tried with sudo gem install bundler -n /usr/local/bin ( Just /usr/bin dint work in my case ).

And then successfully installed bundler

EDIT: I use MacOS, maybe /usr/bin din't work for me for that reason (https://stackoverflow.com/a/34989655/3786657 comment )

Upvotes: 4

Nike Kov
Nike Kov

Reputation: 13753

Update:

According @noraj's answer and @Niels Kristian's comment, the following command should do the job.

gem update --system
bundle install

I wrote this in case someone gets into an issue like mine.

gem install bundler shows that everythings installs well.

Fetching: bundler-1.16.0.gem (100%)
Successfully installed bundler-1.16.0
Parsing documentation for bundler-1.16.0
Installing ri documentation for bundler-1.16.0
Done installing documentation for bundler after 7 seconds
1 gem installed

When I typed bundle there was an error:

/Users/nikkov/.rvm/gems/ruby-2.4.0/bin/bundle:23:in `load': cannot load such file -- /Users/nikkov/.rvm/rubies/ruby-2.4.0/lib/ruby/gems/2.4.0/gems/bundler-1.16.0/exe/bundle (LoadError)
    from /Users/nikkov/.rvm/gems/ruby-2.4.0/bin/bundle:23:in `<main>'
    from /Users/nikkov/.rvm/gems/ruby-2.4.0/bin/ruby_executable_hooks:15:in `eval'
    from /Users/nikkov/.rvm/gems/ruby-2.4.0/bin/ruby_executable_hooks:15:in `<main>'

And in the folder /Users/nikkov/.rvm/rubies/ruby-2.4.0/lib/ruby/gems/2.4.0/gems/ there wasn't a bundler-1.16.0 folder.

I fixed this with sudo gem install bundler

Upvotes: 103

Mathew P. Jones
Mathew P. Jones

Reputation: 853

The reason is your current ruby environment, you got a different version of bundler with the version in Gemfile.lock.

  • Safe way, install bundler with the same version in Gemfile.lock, this won't break anything if there is some incampatibly thing happened.
  • Hard way, just remove Gemfile.lock, and run bundle install.

Upvotes: 23

Antonio Tapiador
Antonio Tapiador

Reputation: 4376

The problem in my case is that the Gemfile.lock file had a BUNDLED_WITH version of 1.16.1 and gem install bundler installed version 2.0.1, so there was a version mismatch when looking to right the folder

gem install bundler -v 1.16.1 fixed it

Of course, you can also change your Gemfile.lock's BUNDLED_WITH with last bundler version and use recent software, as Sam3000 suggests

Upvotes: 418

antonpaisov
antonpaisov

Reputation: 1594

gem update --system

will update the rubygems and will fix the problem.

Upvotes: 149

Georg Keferb&#246;ck
Georg Keferb&#246;ck

Reputation: 1977

Open Gemfile.lock, which is to be found in the root of your app folder. Scroll to the end of the file and see the bundler version used. Then you make sure you install the bundler version used:

gem install bundler -v x.xx.xx

Or - delete the Gemfile.lock and bundle if you have higher bundler version installed.

The choice is yours, my friend.

Upvotes: 5

Sudhanshu
Sudhanshu

Reputation: 15

I had to do rake clean --force. Then did gem install rake and so forth.

Upvotes: -3

noraj
noraj

Reputation: 4652

The real answer is here if you try to install bundler 2.0.1 or 2.0.0 due to Bundler requiring RubyGems v3.0.0

Yesterday I released Bundler 2.0 that introduced a number of breaking changes. One of the those changes was setting Bundler to require RubyGems v3.0.0. After making the release, it has become clear that lots of our users are running into issues with Bundler 2 requiring a really new version of RubyGems.

We have been listening closely to feedback from users and have decided to relax the RubyGems requirement to v2.5.0 at minimum. We have released a new Bundler version, v2.0.1, that adjusts this requirement.

For more info, see: https://bundler.io/blog/2019/01/04/an-update-on-the-bundler-2-release.html

Upvotes: 34

Victor Pudeyev
Victor Pudeyev

Reputation: 4538

I downgraded ruby from 2.5.x to 2.4.x in my particular case.

Upvotes: -3

Wawa Loo
Wawa Loo

Reputation: 2276

If you changed the ruby version you're using with rvm use, remove Gemfile.lock and try again.

Upvotes: 12

Greg Hilston
Greg Hilston

Reputation: 2424

My problem was I'm using RVM and had the wrong Ruby version activated...

Hope this helps at least one person

Upvotes: 1

xhg
xhg

Reputation: 1875

I had the same issue today. I solve this problem by removing any PATH in .bashrc for older rvm.

Upvotes: 2

Related Questions