ruby rbenv - '查找执行的规范':找不到具有可执行包的gem捆绑器(>= 0.a)(Gem::GemNotFoundException)

x6492ojm  于 2022-11-04  发布在  Ruby
关注(0)|答案(7)|浏览(136)

我是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)
我的bundler安装好像有问题,但我不确定是什么问题。用sudo运行gem install bundler并不能解决问题。
下面是完整的跟踪:

$ 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

ui7jx7zq

ui7jx7zq1#

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)2.6是在去年圣诞节发布的,Ruby 2.6 merges bundler gem and use rubygems 3.0.1 as default。从Ruby 2.6开始,你不需要手动安装bundler。

rbenv install 2.6
ntjbwcob

ntjbwcob2#

只是想提一下,我今天在找它的时候发现了这个--并且自己修好了它。
找不到具有可执行包的gem捆绑器(〉= 0.a)(Gem::GemNotFoundException)
我对此一无所知,我是一个幸运的黑客--我注意到在我尝试使用的 checkout 的git repo中有一个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并重新运行了原来的命令,令我非常高兴的是(也是来之不易的),它终于工作了。
我不能100%确定这是否符合"答案“--不要只是盲目地运行我找到的命令,而是考虑重复这个过程,以潜在地揭示你遇到的问题。祝你好运!
编辑以进一步支持:在得出这个结论的同时,我还发现bundle命令会完全失败--但是只在项目目录中--这进一步暗示了它是100%与项目相关的。但通过这种行为,我认为它是在git存储库中加载脚本/可执行文件(就像git的命令可以和工作目录关联一样)所以接下来就是文件结构检查,这时发现了bin文件夹,其中包含一个名为bundle的可执行文件--这就是上面的完整循环。
FWIW -某个比我更了解bundle的人(我不太了解,不知道该向谁报告,或者即使这是异常行为)应该潜在地向他们的github提交一个问题,表明它正在默默地屏蔽他们创建的纯文本错误消息,以引导用户找到正确的解决方案。我让bin/bundle抛出一个退出代码,表示有用的输出将到达stderr,并通过管道将其传递...

htrmnn0y

htrmnn0y3#

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

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

cvxl0en24#

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

vohkndzv

vohkndzv5#

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

wnavrhmk

wnavrhmk6#

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

nwsw7zdq

nwsw7zdq7#

了解您应该使用的捆绑包版本:

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

并安装以下版本:

$ gem install bundler -v  <replace with version>

或者您可以直接运行:

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

相关问题