How to invoke a ruby script (1.9.1) from an environment that's using a different ruby version (2.0.0)?

357 views Asked by At

I am running my Sinatra server with Ruby-2.0.0. I am trying to invoke "chef-client" from the Sinatra app, but I got the following error:

/usr/local/rvm/gems/ruby-2.0.0-p451@global/gems/bundler-1.6.2/lib/bundler/rubygems_integration.rb:252:in `block in replace_gem': chef is not part of the bundle. Add it to Gemfile. (Gem::LoadError)
from /usr/bin/chef-client:22:in `<main>'

The 'chef-client' is using "#!/opt/chef/embedded/bin/ruby". I don't want to install the "chef" gem explicitly in my ruby-2.0.0 gemset, is there a way to ignore the Sinatra Ruby environment settings in this case?

For example

get / do 
  `chef-client`
end

If I do that, I will get error like this

/opt/chef/embedded/lib/ruby/site_ruby/1.9.1/rubygems/dependency.rb:247:in `to_specs': Could not find chef (>= 0) amongst [bundler-1.6.2, bundler-unload-1.0.2, chef-zero-2.0.2, coderay-1.1.0, diff-lcs-1.2.5, erubis-2.7.0, executable-hooks-1.3.1, gem-wrappers-1.2.4, hashie-2.1.1, highline-1.6.21, ipaddress-0.8.0, method_source-0.8.2, mime-types-1.25.1, mixlib-authentication-1.3.0, mixlib-cli-1.5.0, mixlib-cli-1.3.0, mixlib-config-2.1.0, mixlib-log-1.6.0, mixlib-shellout-1.4.0, net-ssh-2.9.1, net-ssh-gateway-1.2.0, net-ssh-multi-1.2.0, net-ssh-multi-1.1, ohai-7.0.4, pry-0.10.0.pre4, rack-1.5.2, rest-client-1.6.8.rc1, rubygems-bundler-1.4.3, rvm-1.11.3.9, slop-3.5.0, systemu-2.5.2, yajl-ruby-1.2.0] (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/chef-client:22:in `<main>'

Thanks!

0

There are 0 answers