rbenv - 'find_spec_for_exe':无法找到带有可执行包的gem bundler(> = 0.a)(Gem :: GemNotFoundException)

问题描述 投票:8回答:5

我是rbenv的新手(长时间使用RVM)。今天我清理卸载我的RVM并安装rbenv。我设法安装Ruby 2.5.1没有任何问题。

但是当我今天尝试为一个项目运行bundle install时,我收到以下错误:

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

看来我的捆绑安装已经破坏了一些东西,但我不确定是什么问题。用gem install bundler运行sudo并不能解决问题。

这是完整的痕迹:

$ 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)

如何解决这个问题?

注意:我使用的是OSX 10.12.6

ruby rubygems bundler rbenv
5个回答
52
投票

bundler was updated from 1.7 to 2 on Jan 4。由于更新,如果您尝试在未指定版本的情况下安装bundler,gem install bundler将从1月4日开始安装版本2。而bundler 2.0要求rubygems版本至少3.0。

首先,使用gem --version检查本地计算机上安装的rubygems。如果你使用ruby v2.5.1,你的rubygems版本将是2.7.x和3.x.

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

在rubygems版本3.x下,gem install bundler命令将无法正常工作。

要解决问题,

1)更新rubygems

gem update --system

2)安装旧版本的bundler

gem install bundler -v 1.17.3

3)安装Ruby 2.6。 2.6于去年圣诞节发布,Ruby 2.6 merges bundler gem and use rubygems 3.0.1 as default。从Ruby 2.6开始,您不需要手动安装bundler。

rbenv install 2.6

5
投票

只是想提一下,我今天在寻找它时发现了这一点 - 并自己修复了它。这是关键;

无法找到带有可执行包的gem bundler(> = 0.a)(Gem :: GemNotFoundException)

我对这一切一无所知,我是一个幸运的黑客 - 我注意到我正在尝试使用的签出的git仓库中有一个bin / bundle可执行文件,并且试图直接从纯粹的绝望中运行它。上面的消息暗示(对我来说)某些可执行文件无法正常工作,而不是它不存在(因为有些搜索缺少所注释的文本,而根本找不到该文件)所以....无论如何。

[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`

嘿,最后一条错误信息有帮助!

因此,我跑了gem install bundler:1.16.6并重新执行了原来的命令,并且为了我的伟大(和来之不易的)快乐,它终于奏效了。

我不是百分之百肯定这适合作为'答案' - 不要盲目地执行我来的命令,而是考虑重复这个过程以潜在地揭示你所遇到的问题。祝好运!

编辑进一步支持:在得出这个结论的同时,我还发现bundle命令会失败批发 - 但仅限于项目目录 - 这进一步暗示它是100%与项目相关的东西。我不知道什么是bundle或者它是如何在内部工作的,但是通过这种行为我认为它是在git repo中的子加载脚本/可执行文件(类似于git的命令如何与工作dirs的上下文相关)所以文件结构检查是下一个。那是在发现bin文件夹的时候,有一个名为bundle的可执行文件 - 它在上面是一个完整的圆圈。

FWIW - 一个比bundle更了解我的人(我不太清楚它知道该向谁报告,或者即使这是异常行为)应该会对他们的github提出一个问题,表明它正在默默掩盖明文错误他们创建的消息是为了引导用户找到合适的解决方案。就个人而言,我有bin/bundle抛出一个退出代码,表明有用的输出来到stderr并通过...


4
投票

这就是我最终解决这个问题的方法:

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

1
投票

我删除了我的Gemfile.lock,之后它工作得很好。


0
投票

我正在使用rbenv 1.1.1和ruby 2.5.1并在运行bundle install时遇到了同样的错误。 gem update --system解决了这个问题


0
投票

有时只在项目目录中运行bundle update --bundler就足够了。

© www.soinside.com 2019 - 2024. All rights reserved.