How to get cron to use the rbenv ruby
With any luck, this will save people my hours of aggravation.
I’m using .rbenv to manage the Ruby processes. When I run everything manually and through the tests, it all works great. Unfortunately, when I put it into cron, it fails.
Step One: Find the rbenv binary:
jason:~$ which ruby
Step Two: Update the cronfile:
In my cronfile, I changed from:
* * * * * cd /home/jason/program-dir ; ruby program.rb
* * * * * cd /home/jason/program-dir ; /home/jason/.rbenv/versions/1.9.3-p194/bin/ruby program.rb
There’s probably a more Linux-fu method, but this worked. If you have a more elegant solution, please drop me a line so that I can update this post.