No candidate version available for 'lsof'


Hello boys and girls ,

I come to you with a strange issue .

I have the following bit of code :

packages = %w( ‘lsof’ )

packages.each do |p|
        package p

Which yields the error

>>>> Caused by Chef::Exceptions::Package: No candidate version available for 'lsof'
/opt/chef/embedded/lib/ruby/gems/2.4.0/gems/chef-13.8.5/lib/chef/mixin/why_run.rb:240:in `run'
/opt/chef/embedded/lib/ruby/gems/2.4.0/gems/chef-13.8.5/lib/chef/mixin/why_run.rb:321:in `block in run'
/opt/chef/embedded/lib/ruby/gems/2.4.0/gems/chef-13.8.5/lib/chef/mixin/why_run.rb:320:in `each'
/opt/chef/embedded/lib/ruby/gems/2.4.0/gems/chef-13.8.5/lib/chef/mixin/why_run.rb:320:in `run'

BUT on the other side , if I comment out that code and put instead just

package 'lsof'

Then it works just fine . Can anyone just tell me where i am doing wrong ?


The convenience of using the %w literal to construct arrays in ruby is that it allows/requires you to leave out the quotes on your string. So packages = %w( 'lsof' ) is actually creating an array with the string '\'lsof\'' which includes the quotes. This is probably what makes the error message No candidate version available for 'lsof' look normal as well. Changing to packages = %w(lsof) will work.


Hello and thank you ccrebolder,

May i complete you by saying that A = %w ( a , b , c ) , will actually result in A[0] = a ; A[1] = , ; A[2] = b ; A[3] = , and so on …

Jeez better use safer code like Java/C/C++ similar style : A = [ “a” , “b” , “c” ] :slight_smile:

Thank you for the response man , never thought it was my ruby code, i was blaming it on chef :slight_smile: