4

I am having issues when setting up Chef and Vagrant for my rails app. When I try:

$ vagrant up

I get the error:

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

Then when I run gem env, I get:

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 is installed, as well as, ChefDK. I also made sure to add:

PATH=$HOME/.chefdk/gem/ruby/2.1.0/bin:/opt/chefdk/bin:$PATH to my .bash_profile.

Any help would be much appreciated!

Bryan Saxon
  • 653
  • 1
  • 7
  • 21

4 Answers4

8

vagrant-berkshelf support only Berkshelf installed by Chef-DK.

You need to remove Chef & Berkshelf install by gem.

gem uninstall chef chef-zero berkshelf knife-solo

And install Chef-DK from chef website https://downloads.getchef.com/chef-dk, new version contain all of these tools


EDIT

If you use Kitchen, you need keep Berkshelf install by gem follow this post for know how do that : https://stackoverflow.com/a/28221417/3271231

Community
  • 1
  • 1
Pierozi
  • 352
  • 2
  • 4
3

Also check C:\opscode\chefdk\bin is before the embedded\bin in your PATH. You can check with 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
KCD
  • 9,873
  • 5
  • 66
  • 75
2

I see from the output you posted that you are using RBENV and I think this may be what's causing your issues.

ChefDK comes with its own embedded Ruby. All the gems for ChefDK (chef-client, berkshelf etc) are stored with the embedded ruby and are not visible to system ruby or any rubies managed by RBENV/RVM. They get loaded by the executables using the embedded ChefDK ruby.

I've had similar problems to you and I avoid using RBENV/RVM with ChefDK wherever possible.

If you really need the version manager for other stuff like multiple ruby/rails setups, I've had success by making sure the ChefDK path elements come before RBENV related path elements.

To manipulate ChefDK related gems use the chef gem command instead of the normal gem command so they get added to the embedded ruby instead of the system ruby.

Hope this helps you figure it out.

Tricky
  • 182
  • 5
0

Check your version of vagrant-berkshelf, newer versions should grok how to make it use the berks from ChefDK a bit better. That said, I would definitely look in to switch over to Test Kitchen even if you still use Vagrant under the hood, it is included with ChefDK and handles this issue much more smoothly.

coderanger
  • 52,400
  • 4
  • 52
  • 75