If you are using Chef to manage your server deployments (and you should be!), then you'll likely have run into the situation where you install a new system Ruby and need to install a few system-wide gems to bootstrap your install (think Bundler/Rake).

However, when you install the system ruby, and use the standard Chef gem install resource:

gem_package "bundler"

then you will run into trouble as Chef will try to use the original system ruby binary when installing the gem for you.

The Fix

After some Googling, and time on StackOverflow, I've put together a workable solution. All it does it reload the Ohai resource (updating information about your system/Ruby binary), and performs the gem installation in a ruby_block so that it does not run at compile-time.

# Install system Ruby

## install ruby here....

# Install gems in new ruby

# Need to reload OHAI to ensure the newest ruby is loaded up
ohai "reload" do
  action :reload

["bundler", "rake", "...."].each do |gem_to_install|
  ruby_block "install #{gem_to_install} in new ruby" do
    block do
      g =
      g.gem_binary "#{node['languages']['ruby']['bin_dir']}/gem"
    action :create

That ought to do it! Hope it saves someone some time....

Blog Logo

Brandon Parsons



Brandon Parsons

My Personal Blog

Head back to the main page