[RESOLVED] Ruby versions - chef, application, cookbooks, gems etc


Sorry, but this is probably going to be a newbie question since I have no real knowledge of ruby, gems or chef. I am confused about how different ruby versions relate to the chef resources (cookbooks, recipes etc) on my local PC, the version the application requires, and what is available on the application server (where chef client runs). We manage ruby versions using rbenv.

We have a web application that requires ruby version 2.1.2. On my local PC, from which we manage chef, I can see that versions 2.1.2, 2.3.1 and the system version of 2.3.3 are available. Version 2.1.2 has been set as the global version on the PC. On the (web) application server I can see that versions 2.0.0, 2.1.1 and 2.1.2 are available. Version 2.1.2 has been set as the global version on the server.

Several of the cookbooks (from the chef supermarket) are quite old. If we try and upgrade them some give a dependency error that we need to use ruby version 2.2 (for example) or above. If I change the PC global version to (for example) 2.3.3, then it seems that the local gems are missing for that version. So I assume I need to reinstall all the gems for that version (using ‘bundle install’ if I remember correctly)?
If we then upload the cookbooks to the (opscode) chef server, and these are downloaded to the application server when I run ‘chef-client’, I assume the app server needs to have the same version of ruby installed as well? How does chef client know which version of ruby to use, and will this interfere in any way with the global version which is set according to the version required by the application, not the version required by chef client?

I assume this is how things are supposed to work - the application uses one version of ruby (installed on the app server and set as global), chef client can use a different version (also installed on the app server), and the local PC also uses the same version as chef client on the app server? That way we can update cookbooks and gems on the PC, and use the latest ruby version, without it affecting the actual web app or its running on the app server. Does that sound right?



Hi John,

When you install chef-client or ChefDK as provided by Chef Software, those installers come with their own embedded Ruby which is what chef-client and tooling use such that we don’t have to worry about what is installed on the system. The Chef DSL has resources like chef_gem which allows you to install gems to the Chef embedded Ruby and gem_package which allows you to specify arbitrary gem binaries. For the most part, the version of Ruby doesn’t come into play with cookbooks or recipes unless they are using a gem themselves. In those cases that’s probably what is complaining about the version of Ruby.

Hopefully that clears up at least part of it.


Thanks for that. I have now updated my PC ruby (via rbenv) to version 2.4.1, and nothing on the app has broken :slight_smile:

I have updated the local gems, which now no longer complain about the ruby version. I have also updated where possible the cookbooks, but some, such as mysql, have breaking changes (to cater for mysql 6.x onwards, and we are still using 5.7). As far as I can tell we either have to keep back some older versions of things because of the underlying software version, or upgrade to the latest cookbook versions and reconfigure the app servers to cater for the breaking changes. The former choice is not good in case chef itself changes and the cookbook starts to fail (which is exactly the problem that started all of this).