Gem install using chef still picks the older ruby version

‘which ruby’ returns me the latest ruby version installed which is 2.2.3.
‘which -a ruby’ returns 2 paths. one is 1.9

But the latest one is set as the default ruby for executing my chef recipe. But still when I execute a gem install using chef it takes the older version of ruby (1.9) and gives an error
‘rake requires Ruby version >= 2.0.0.’

Any idea why is this ?

Hello @meeramarygeorge ,

The good practice is to have control over the versions, so I recommend you to:

  1. Install RVM (Ruby Version Manager):
    RVM: Ruby Version Manager - Installing RVM

  2. Switch to the proper Ruby version:
    RVM: Ruby Version Manager - 'rvm default' - setting default ruby for new terminals

  3. Try to install the gem again.

Good luck!