Problems between Chef Ruby and system Ruby

Hello,

I'm very new to Chef and going over the tutorials plus the Learning Chef
book by O'Reilly. Everything is going very smooth but I'm having issues
keeping the system Ruby and Chef Ruby working separate from each other.

One of the issues I found is working with test kitchen.

$ /opt/chefdk/bin/kitchen list
!!!!!! The berkshelf' gem is missing and must be installed or cannot be properly activated. Run gem install berkshelfor add the following to your Gemfile if you are using Bundler:gem 'berkshelf'`.

------Exception-------
Class: Kitchen::UserError
Message: Could not load or activate Berkshelf (can't activate
json-1.7.7, already activated json-1.8.1)

Please see .kitchen/logs/kitchen.log for more details
Also try running kitchen diagnose --all for configuration

I checked and found that the issue appears to be the system Gem is
referencing a different version from the Chef Gem.

$ gem list | grep json
json (1.7.7)

$ /opt/chefdk/embedded/bin/gem list | grep json
fog-json (1.0.0)
json (1.8.1, 1.7.7)
multi_json (1.10.1)

I know that many people are using RVM, but I had troubles making this work
and would like to know what is best practice (from a newbie point of view).

Thanks so much!
Robert

I had the same issue...If you want to use the version of ruby that came
with ChefDK do the following…assuming you are using BASH…
Do: echo 'eval "$(chef shell-init bash)"' >> ~/.bash_profile
Worked for me.

Seth Floyd

On Tue, Dec 23, 2014 at 7:09 PM, Robert Freiberger rfreiberger@gmail.com
wrote:

Hello,

I'm very new to Chef and going over the tutorials plus the Learning Chef
book by O'Reilly. Everything is going very smooth but I'm having issues
keeping the system Ruby and Chef Ruby working separate from each other.

One of the issues I found is working with test kitchen.

$ /opt/chefdk/bin/kitchen list
!!!!!! The berkshelf' gem is missing and must be installed or cannot be properly activated. Run gem install berkshelfor add the following to your Gemfile if you are using Bundler:gem 'berkshelf'`.

------Exception-------
Class: Kitchen::UserError
Message: Could not load or activate Berkshelf (can't activate
json-1.7.7, already activated json-1.8.1)

Please see .kitchen/logs/kitchen.log for more details
Also try running kitchen diagnose --all for configuration

I checked and found that the issue appears to be the system Gem is
referencing a different version from the Chef Gem.

$ gem list | grep json
json (1.7.7)

$ /opt/chefdk/embedded/bin/gem list | grep json
fog-json (1.0.0)
json (1.8.1, 1.7.7)
multi_json (1.10.1)

I know that many people are using RVM, but I had troubles making this work
and would like to know what is best practice (from a newbie point of view).

Thanks so much!
Robert

sorry for the half mail :slight_smile:
Check where is your ruby: which ruby
check if anything is pointing to GEM_PATH or GEM_HOME , etc . env would
show all.
rvm or rbenv system wide installation can do this. I use omnibus chef, and
i prefer to run them with env -i /opt/chef/foo.rb . Some time things break
due to certain environment variable not being set like HOME, PATH, LC_*
etc. You can set environment variables explicitly. env -i FOO=BAR
/opt/chef/embedded/bin/ruby foo.rb . etc.

On Tue, Dec 23, 2014 at 5:23 PM, Seth Floyd seth@sethfloydjr.com wrote:

I had the same issue...If you want to use the version of ruby that came
with ChefDK do the following…assuming you are using BASH…
Do: echo 'eval "$(chef shell-init bash)"' >> ~/.bash_profile
Worked for me.

Seth Floyd

On Tue, Dec 23, 2014 at 7:09 PM, Robert Freiberger rfreiberger@gmail.com
wrote:

Hello,

I'm very new to Chef and going over the tutorials plus the Learning Chef
book by O'Reilly. Everything is going very smooth but I'm having issues
keeping the system Ruby and Chef Ruby working separate from each other.

One of the issues I found is working with test kitchen.

$ /opt/chefdk/bin/kitchen list
!!!!!! The berkshelf' gem is missing and must be installed or cannot be properly activated. Run gem install berkshelfor add the following to your Gemfile if you are using Bundler:gem 'berkshelf'`.

------Exception-------
Class: Kitchen::UserError
Message: Could not load or activate Berkshelf (can't activate
json-1.7.7, already activated json-1.8.1)

Please see .kitchen/logs/kitchen.log for more details
Also try running kitchen diagnose --all for configuration

I checked and found that the issue appears to be the system Gem is
referencing a different version from the Chef Gem.

$ gem list | grep json
json (1.7.7)

$ /opt/chefdk/embedded/bin/gem list | grep json
fog-json (1.0.0)
json (1.8.1, 1.7.7)
multi_json (1.10.1)

I know that many people are using RVM, but I had troubles making this
work and would like to know what is best practice (from a newbie point of
view).

Thanks so much!
Robert

I have the same problem and running the latest version of ChefDK. Using ruby from ChefDK...

$ chef --version
Chef Development Kit Version: 0.17.17
chef-client version: 12.13.37
delivery version: master (f68e5c5804cd7d8a76c69b926fbb261e1070751b)
berks version: 4.3.5
kitchen version: 1.11.1

$ env | grep GEM
GEM_HOME=/Users/wunr002/.chefdk/gem/ruby/2.1.0
GEM_ROOT=/opt/chefdk/embedded/lib/ruby/gems/2.1.0
GEM_PATH=/Users/wunr002/.chefdk/gem/ruby/2.1.0:/opt/chefdk/embedded/lib/ruby/gems/2.1.0

$ ruby --version
ruby 2.1.8p440 (2015-12-16 revision 53160) [x86_64-darwin13.0]

$ kitchen verify
-----> Starting Kitchen (v1.11.1)
!!!!!! The berkshelf' gem is missing and must be installed or cannot be properly activated. Run gem install berkshelfor add the following to your Gemfile if you are using Bundler:gem 'berkshelf'`.

------Exception-------
Class: Kitchen::UserError
Message: Could not load or activate Berkshelf (cannot load such file -- berkshelf)

Please see .kitchen/logs/kitchen.log for more details
Also try running kitchen diagnose --all for configuration