在90个总宝石中找不到'berkshelf'(> = 0)(Gem :: LoadError)

时间:2015-01-05 00:49:06

标签: ruby-on-rails vagrant chef rbenv

我在为rails应用程序设置Chef和Vagrant时遇到问题。当我尝试:

$ vagrant up

我收到错误:

Bringing machine 'default' up with 'virtualbox' provider...
The following berks command failed to execute:

    /Users/user/.chefdk/gem/ruby/2.1.0/bin/berks --version --format json

The stdout and stderr are shown below:

stdout: 
stderr: /opt/chefdk/embedded/lib/ruby/site_ruby/2.1.0/rubygems/dependency.rb:313:in `to_specs':                        
    Could not find 'berkshelf' (>= 0) among 90 total gem(s) (Gem::LoadError)
    Checked in 'GEM_PATH=/Users/user/.vagrant.d/gems:/Applications/Vagrant/bin/../embedded/gems', execute `gem env` for more information
    from /opt/chefdk/embedded/lib/ruby/site_ruby/2.1.0/rubygems/dependency.rb:322:in `to_spec'
    from /opt/chefdk/embedded/lib/ruby/site_ruby/2.1.0/rubygems/core_ext/kernel_gem.rb:58:in`gem'
    from /Users/user/.chefdk/gem/ruby/2.1.0/bin/berks:22:in `<main>'

然后当我运行gem env时,我得到:

RubyGems Environment:
- RUBYGEMS VERSION: 2.2.0
- RUBY VERSION: 2.1.0 (2013-12-25 patchlevel 0) [x86_64-darwin14.0]
- INSTALLATION DIRECTORY: /Users/user/.rbenv/versions/2.1.0/lib/ruby/gems/2.1.0
- RUBY EXECUTABLE: /Users/user/.rbenv/versions/2.1.0/bin/ruby
- EXECUTABLE DIRECTORY: /Users/user/.rbenv/versions/2.1.0/bin
- SPEC CACHE DIRECTORY: /Users/user/.gem/specs
- RUBYGEMS PLATFORMS:
- ruby
- x86_64-darwin-14
- GEM PATHS:
  - /Users/user/.rbenv/versions/2.1.0/lib/ruby/gems/2.1.0
  - /Users/user/.gem/ruby/2.1.0
- GEM CONFIGURATION:
  - :update_sources => true
  - :verbose => true
  - :backtrace => false
  - :bulk_threshold => 1000
  - "gem" => "--no-document"
- REMOTE SOURCES:
  - https://rubygems.org/
- SHELL PATH:
  - /Users/user/.rbenv/versions/2.1.0/bin
  - /usr/local/Cellar/rbenv/0.4.0/libexec
  - /Users/user/.chefdk/gem/ruby/2.1.0/bin
  - /opt/chefdk/bin
  - /Users/user/.rbenv/shims
  - /Users/user/.chefdk/gem/ruby/2.1.0/bin
  - /opt/chefdk/bin
  - /opt/chef/embedded/bin
  - /usr/local/bin
  - /Library/Frameworks/Python.framework/Versions/3.4/bin
  - /Users/user/.rbenv/shims
  - /Users/user/.chefdk/gem/ruby/2.1.0/bin
  - /opt/chefdk/bin
  - /opt/chef/embedded/bin
  - /usr/local/bin
  - /Library/Frameworks/Python.framework/Versions/3.4/bin
  - /Users/user/.chefdk/gem/ruby/2.1.0/bin
  - /opt/chefdk/bin
  - /Users/user/.rbenv/shims
  - /opt/chef/embedded/bin
  - /usr/local/bin
  - /Library/Frameworks/Python.framework/Versions/3.4/bin
  - /Users/user/.rbenv/shims
  - /Users/user/.rbenv/bin
  - .git/safe/../../bin
  - /Users/user/.rbenv/shims
  - /Users/user/.bin
  - /usr/local/sbin
  - /usr/local/bin
  - /usr/bin
  - /bin
  - /usr/sbin
  - /sbin
  - /opt/X11/bin
  - /Users/user/Documents/AppFiles/gsutil
  - /Applications/Postgres.app/Contents/Versions/9.3/bin
  - /Users/user/.rvm/bin
  - /usr/sbin
  - /Users/user/.rvm/bin
  - /Users/user/Documents/AppFiles/gsutil
  - /Applications/Postgres.app/Contents/Versions/9.3/bin
  - /Users/user/.rvm/bin
  - /usr/sbin
  - /Users/user/.rvm/bin
  - /Users/user/Documents/AppFiles/gsutil
  - /Applications/Postgres.app/Contents/Versions/9.3/bin
  - /Users/user/.rvm/bin
  - /usr/sbin
  - /Users/user/.rvm/bin

安装了Berkshelf,以及ChefDK。我还确保添加:

PATH=$HOME/.chefdk/gem/ruby/2.1.0/bin:/opt/chefdk/bin:$PATH到我的.bash_profile。

非常感谢任何帮助!

4 个答案:

答案 0 :(得分:8)

vagrant-berkshelf仅支持由Chef-DK安装的Berkshelf。

你需要删除Chef&amp; Berkshelf由gem安装。

gem uninstall chef chef-zero berkshelf knife-solo

从主厨网站https://downloads.getchef.com/chef-dk安装Chef-DK,新版本包含所有这些工具


修改

如果你使用Kitchen,你需要通过gem 保持Berkshelf安装 按照这篇文章了解如何做到:https://stackoverflow.com/a/28221417/3271231

答案 1 :(得分:3)

同时检查C:\opscode\chefdk\bin是否在PATH中的embedded\bin之前。您可以查看chef -v

chef -v
WARN: C:/opscode/chefdk/embedded/bin is before C:/opscode/chefdk/bin in your Path, please reverse that order.
WARN: consider using the correct `chef shell-init <shell>` command to setup your environment correctly.
Chef Development Kit Version: 0.4.0

答案 2 :(得分:2)

我从您发布的输出中看到您正在使用RBENV,我认为这可能是导致您出现问题的原因。

ChefDK自带嵌入式Ruby。 ChefDK(chef-client,berkshelf等)的所有宝石都与嵌入的ruby一起存储,系统ruby或RBENV / RVM管理的任何红宝石都看不到。它们使用嵌入式ChefDK ruby​​由可执行文件加载。

我遇到了类似的问题,我尽可能避免将RBENV / RVM与ChefDK一起使用。

如果您确实需要版本管理器来处理其他内容,例如多个ruby / rails设置,我确保ChefDK路径元素在RBENV相关路径元素之前就已经成功。

要操作ChefDK相关的gem,请使用chef gem命令而不是普通的gem命令,这样它们就会被添加到嵌入式ruby而不是系统ruby中。

希望这有助于你弄明白。

答案 3 :(得分:0)

检查你的vagrant-berkshelf版本,新版本应该如何让它更好地使用ChefDK的berks。也就是说,即使你仍然使用Vagrant,我肯定会切换到测试厨房,它包含在ChefDK中,可以更顺畅地处理这个问题。