4

I have chef 11.4.4 which has ruby 1.9.1 installed. I want to install berkshelf but it requires ruby 1.9.2 or later. I installed ruby 2.0.0-p247 (latest stable) with rvm. When i run a knife command I get ...

# knife help 
/opt/chef/embedded/lib/ruby/site_ruby/1.9.1/rubygems/dependency.rb:247:in `to_specs': Could not find chef (>= 0) amongst [rake-10.1.0, rvm-1.11.3.8] (Gem::LoadError)
from /opt/chef/embedded/lib/ruby/site_ruby/1.9.1/rubygems/dependency.rb:256:in `to_spec'
from /opt/chef/embedded/lib/ruby/site_ruby/1.9.1/rubygems.rb:1231:in `gem'
from /usr/bin/knife:22:in `<main>'

If I switch it back to the system version, which is the version of ruby embedded with chef, it works again.

# rvm use system
Now using system ruby.
# knife help
Usage: knife SUBCOMMAND (options)
.
.
.

I've googled around for ways to upgrade ruby to 2.0.0x for chef but no luck. I like the ability to switch ruby versions so easily. It would be great if chef could do the same but just getting it to work with the latest stable or even 1.9.2 version of ruby would be great. Thanks!

Ryan B.
  • 353
  • 4
  • 13
  • Chef 11.4.4 has known problems with Ruby 2.0 (rubygems 2.0.x in fact as the format changed). Try to install an old version of rubygem, for example 1.8.25 `gem update --system 1.8.25` or switch to 1.9.3-p448 for the time being. I solved the chef-solo problem by doing so. – Terry Wang Jul 05 '13 at 00:31
  • Thanks. This helped. I switch to 1.9.3 and installed the chef gem and it worked. – Ryan B. Jul 06 '13 at 06:24
  • I'll make it a reply and add some more info. It should be useful to many others run into the same issue, please vote it up later:-) – Terry Wang Jul 06 '13 at 12:16

3 Answers3

10

You need to use a ruby with rvm:

rvm use 2.0.0-p247

this will set up environment to use that ruby, you can set it default for new shells/sessions with:

rvm alias create default 2.0.0 #OR:
rvm use 2.0.0 --default

It is also required to install the gems again as you switch to new ruby:

gem install chef
mpapis
  • 52,729
  • 14
  • 121
  • 158
  • Thanks for the tip. I ran the commands as you listed but the last command failed: # gem install chef ^@ERROR: Could not find a valid gem 'chef' (>= 0), here is why: Unable to download data from https://rubygems.org/ - Errno::ETIMEDOUT: Connection timed out - connect(2) (https://rubygems.org/latest_specs.4.8.gz) ERROR: Possible alternatives: chef – Ryan B. Jul 06 '13 at 06:16
  • continuation... After it didn't work I switched to 1.9.3 as suggested by @Terry wang, then re ran the commands you gave and it worked! Thanks. – Ryan B. Jul 06 '13 at 06:29
  • the part where we need to install chef again makes more sense !! – ufdeveloper Nov 27 '13 at 05:37
  • This worked for me. Note, do *not* install chef via the omnibus installer if using rvm. – brianz Jan 24 '14 at 22:53
5

It's neither Chef 11.4.4 nor Ruby 2.0.0's fault, but rubygems 2.0.x;-)

See => CHEF-3933

Workaround is to install an older version of rubygemsTry to install an old version of rubygems, for example 1.8.25 gem update --system 1.8.25 or switch to 1.9.3-p448 for the time being.

I solved the chef-solo run problem anyway.

More info:

Terry Wang
  • 13,840
  • 3
  • 50
  • 43
  • I see. Thanks for the link. I didn't consider the 3rd piece, rubygems. It looks pretty straight forward. Before I switch ruby back to 2.0.x, and set rubygems to 1.8.25, should I be concerned if a large version gap between ruby and rubygems exist? Don't I want to keep these 2 relatively close? Thanks. – Ryan B. Jul 09 '13 at 01:13
  • I think there is not much to be worried. Once `Chef` fixes the issue in new versions, we should be able to stay on the latest Ruby + rubygems ;-) – Terry Wang Jul 09 '13 at 06:11
  • Installing the older version of rubygems worked for me after I had also installed an older version of json `gem install json -v 1.7.7`. – Kevin Cross Jul 12 '13 at 10:13
  • I've decided to to stick with 1.8.25 for now at least. Thanks for the assist! – Ryan B. Jul 18 '13 at 16:34
3

rvm reset should fix the problem.

When you switch ruby version with rvm use you need to rvm reset again though.

zekus
  • 848
  • 8
  • 16