Tabrez
Tabrez

Reputation: 3466

Getting GEM LOAD error when I run a ruby utility on Mac

I am running Mac OS X 10.7.2 (Lion). It came with ruby 1.8.7. I have installed 1.9.2 and set it as the default (via rvm use).

In fact I get the same ruby version for the following commands:

>ruby --version
ruby 1.9.2p290 (2011-07-09 revision 32553) [x86_64-darwin11.2.0]

>sudo ruby --version
Password:
ruby 1.9.2p290 (2011-07-09 revision 32553) [x86_64-darwin11.2.0]

However, if I try to run a ruby based utility with the sudo command, it gives me a "gem load error":

~/chef-repo>sudo chef-client
Password:
~/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/site_ruby/1.9.1/rubygems/dependency.rb:247:in `to_specs': Could not find chef (>= 0) amongst [minitest-1.6.0, rake-0.8.7, rdoc-2.5.8] (Gem::LoadError)
    from ~/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/site_ruby/1.9.1/rubygems/dependency.rb:256:in `to_spec'
    from ~/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/site_ruby/1.9.1/rubygems.rb:1210:in `gem'
    from ~/.rvm/gems/ruby-1.9.2-p290/bin/chef-client:18:in `<main>'

If I run the same utility directly it runs without any problems but fails later (not due to gem load issues but due to access rights on other folders that are root-only).

~/chef-repo>chef-client
[Tue, 29 Nov 2011 11:11:55 -0500] INFO: *** Chef 0.10.4 ***
[Tue, 29 Nov 2011 11:12:00 -0500] INFO: Client key /etc/chef/client.pem is not present - registering
[Tue, 29 Nov 2011 11:12:00 -0500] INFO: HTTP Request Returned 409 Conflict: Client already exists.
~/.rvm/gems/ruby-1.9.2-p290/gems/chef-0.10.4/lib/chef/mixin/create_path.rb:49:in `mkdir': Permission denied - /var/chef (Errno::EACCES)

Has anyone else run into this problem? Does anyone know the solution? I do need to run this with sudo to avoid other errors down the line.

Upvotes: 3

Views: 1621

Answers (2)

Terry Su
Terry Su

Reputation: 119

Try

sudo gem install chef

It will allow you to run chef without sudo or rvmsudo. It works for me.

Upvotes: 0

lucapette
lucapette

Reputation: 20724

Try

rvmsudo chef-client

It should work fine.

Upvotes: 2

Related Questions