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

17

278

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

Now I have:

  • gem -v 2.6.14
  • ruby -v ruby 2.3.5p376 (2017-09-14 revision 59905) [x86_64-darwin15]
  • jekyll -v jekyll 3.6.2
  • bundle -vBundler version 1.16.0.pre.3

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!

Kingston answered 31/10, 2017 at 0:26 Comment(2)
Can this help maybe: github.com/rvm/rvm/issues/1860Stereopticon
@Stereopticon thanks for that! I tried it, now got a new error on the process: #47035580Kingston
V
416

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

Vandusen answered 4/1, 2019 at 11:37 Comment(7)
As an alternative, you may wish to change the BUNDLED_WITH version to the latest version of bundler. This worked for me and also saved me needing outdated software :)Cologarithm
Bundler 2 just got released, so if you are not specifying as above in your Dockerfile, you are going to hit this error bundler.io/blog/2019/01/03/announcing-bundler-2.htmlDurer
Hi @antonio-tapiador I'm having this issue, but i'm on windows (can't switch to linux). I've run gem install bundler -v 1.16.1 and now if aI run gem.bat list bundler I get bundler (2.0.1, 1.16.1, 1.9.6). I cant change the current version: executing bundle.bat _1.16.1 install gives me this error: Could not find command "_1.16.1". Do you have any idea, so I don't have to create a new question? Thanks!Arielle
Never mind, I was missing an underscore at the end of the version.Arielle
Thanks. This also solve my same problem using ruby v2.5.1p57Hex
For CI, I'm now using bundler_version=$(grep -A 1 'BUNDLED WITH' Gemfile.lock | grep -o -P "[\d.]+"); gem install bundler -v $bundler_version to dynamically install the version needed.Espalier
I'm getting You don't have write permissions for the /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/gems/2.6.0 directory. while executing the gem install bundler. Even with sudo. any idea?Grumous
S
148
gem update --system

will update the rubygems and will fix the problem.

Stripy answered 9/1, 2019 at 21:3 Comment(5)
Just to clarify - as @noraj points out - the problem was introduced in the new version of bundler. If you follow the link, the solution is to update RubyGems.Silin
gem update --system worked for me: ruby 2.5.0, bundler 2.0.1, macOS 10.13.6.Soberminded
@ReggieB: What link?Gershon
@Gershon bundler.io/blog/2019/01/04/…Silin
this command actually created this issue for me!London
F
103

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

Finger answered 9/11, 2017 at 12:20 Comment(7)
After you "fix" it, make sure you fix your directory permissions on .rvm and .gemKourtneykovac
@Kourtneykovac explain more detailed please, buy editing my answerFinger
@Kourtneykovac chrs for your answer - would you pls be able to elaborate what you mean by fix your directory permissions on .rvm and .gem?Palatinate
@Nik kov the location of .rvm and .gem folders are probably inside your home folder. Try to change the permissions of them by chmod command. It worked for me.Gouda
What @souravirus said... Permissions need to be open enough on those directories, else failure.Kourtneykovac
Would love for someone to elaborate on what chmod permissions they granted here that worked.Courbevoie
sudo gem install is bad practice, in normal case all gem install should work without sudoAstraea
S
60

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: https://stackoverflow.com/posts/54083113/revisions

Surf answered 24/1, 2019 at 12:47 Comment(5)
I'm using Visual Studio Code and uploading and publishing via Azure Devops, which is where it was failing on Build., I just deleted the lock file locally, committed and then pushed. The Build was failing on the Install Gems step but now it works.Valorievalorization
For an existing production project this is a terrible idea. You will end up installing a bunch of untested (with your system) new code.Concerned
Yes, this is a bad idea and should not be considered a fix. It does prove that the other answer (about having a mismatched Bundler version) is correct. Installing the correct version of Bundler should fix it.Abey
Thanks @RobinDaugherty, I've edited the answer to warn everyone not to do it in production.Surf
This shouldn't be done in development either. There's a good reason for the lock file, it shouldn't be deleted in an existing project. Installing the correct version of bundler on your machine fixes the problem, deleting Gemfile.lock should be considered a last resort since it can lead to other problems.Abey
R
34

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

Referendum answered 7/1, 2019 at 23:5 Comment(5)
Thanks, your link saved me some time from googling the problemDelocalize
Capistrano was failing on a new machine but not old ones. This fixed the issue for me.Unionize
It can't be "the real answer" to the OP's question because Bundler 2.0 didn't exist in 2017, although people will certainly find this page because the symptoms are the same.Jeffery
I am experiencing the problem with bundler 2.0.1Pilot
Here are other breaking changes in version 2.0.0: github.com/bundler/bundler/releases/tag/v2.0.0Brambly
A
23

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.
Absa answered 29/1, 2019 at 2:50 Comment(1)
Thanks for that. Definitely everybody should use the safe version to don't mess up the environment with newly untested gems. To install bundler with specific version e.g. 1.17 use gem install bundler -v 1.17Mirella
J
18

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

gem install bundler -v "$(grep -A 1 "BUNDLED WITH" Gemfile.lock | tail -n 1)"
Jeopardize answered 28/3, 2020 at 20:55 Comment(1)
This fixed it for me. Ultimately, install the expected bundler. SimplesKissinger
L
12

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

Lasting answered 6/12, 2018 at 8:0 Comment(0)
D
5

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.

Drum answered 8/1, 2019 at 14:45 Comment(3)
I would not recommend deleting the Gemfile.lock because that would also update all gems. This can lead to huge problems.Alcinia
@SandroL - totally agree with your statement. However, it is an option to those who are risk takers and drawn to drama.Scepter
Thank you. Installing the version I had in the Gemfile.lock folder did the trick!Nonaggression
H
5

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

Hospitalet answered 21/2, 2020 at 18:11 Comment(1)
I hit the same issue. I was setting GEM_HOME, GEM_PATH and BUNDLE_PATH to /gems inside of my docker-compose.yml. Unsetting those and rebuilding fixed it, though I would prefer to figure out the nuance of setting these to /gems and still having things like rails new ... work...Borosilicate
M
4

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://mcmap.net/q/81361/-how-do-i-fix-the-quot-you-don-39-t-have-write-permissions-into-the-usr-bin-directory-quot-error-when-installing-rails comment )

Muraida answered 4/12, 2019 at 20:40 Comment(0)
D
2

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

Deangelo answered 5/6, 2018 at 20:29 Comment(1)
You save me I had export PATH="$PATH:$HOME/.rvm/bin" in my bashrc, I remove it and it worksThespian
G
1

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

Hope this helps at least one person

Gardener answered 7/8, 2018 at 18:33 Comment(0)
S
1

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

Septum answered 20/10, 2023 at 11:57 Comment(0)
P
-2

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.

Polyphonic answered 31/7, 2022 at 11:17 Comment(0)
M
-3

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

Mcguinness answered 11/9, 2018 at 14:19 Comment(0)
L
-3

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

Lasso answered 5/1, 2019 at 20:44 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.