3

I'm trying to figure out how to reference a gem binary in Chef, and it just occurred to me that gems are always loaded up in a 1.9.1 directory, rather than 1.9.3....

Could anyone explain this?

Will this change if/when I move to Ruby 2? Don't want to hardcode 1.9.1 if it is going to change....

Thanks!

Brandon
  • 3,091
  • 2
  • 34
  • 64

2 Answers2

1

In chef, you can find the directory where rubygems creates executables in in node["languages"]["ruby"]["bin_dir"]. You should thus never hardcode these paths in your recipes as they can change.

As for your exact question: In Ruby >= 1.9.1 and < 2.0.0, rubygems installs gems into a 1.9.1 directory to denote its usage of the 1.9.1 ABI. The intention was that gems compiled against that can be used interchangeably between different ruby versions using this ABI. However, in practice this turned out to be more difficult...

Ruby 2.0.0 uses the 2.0.0 directory. Again, you should not hardcode the paths but use the node attribute (set by OHAI using rubygem's own facilities).

ian
  • 12,003
  • 9
  • 51
  • 107
Holger Just
  • 52,918
  • 14
  • 115
  • 123
  • Thanks for the specific answer to my question, and some backstory!! – Brandon Mar 03 '13 at 00:36
  • If I install a new system ruby during a chef recipe, will this path be updated so I can do a `gem_package` to install a gem with the new ruby? @iain @holger just – Brandon Mar 03 '13 at 00:37
  • if you change the ruby in comparison to the very start of the chef run, you have to use the `ohai` resource to reload the information. Also, you should make sure to do that before any other gem is installed to ensure consistent install targets. – Holger Just Mar 03 '13 at 09:59
0

You can always use:

$ gem env gemdir

or

$ gem env gempath

to get your gems directory.

Hauleth
  • 22,873
  • 4
  • 61
  • 112