How to get cron to use the rbenv ruby

Friday, June 1st, 2012

With any luck, this will save people my hours of aggravation.

My problem:

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.

My solution:

Step One: Find the rbenv binary:

jason:~$ which ruby
/home/jason/.rbenv/shims/ruby

Step Two: Update the cronfile:

In my cronfile, I changed from:

* * * * * cd /home/jason/program-dir ; ruby program.rb

to

* * * * * cd /home/jason/program-dir ; /home/jason/.rbenv/versions/1.9.3-p194/bin/ruby program.rb

Voila.

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.

Sharing is Caring:

Comments