How to run a Ruby script using rbenv with cron

I’ve found a solution to load rbenv. Either with a loader importing rbenv to the PATH :

*/1 * * * * /bin/bash -c ‘. $HOME/.rbenv/loader.sh ; cd /data/app/; ruby -v’

The ‘.’ before ‘$HOME/.rbenv/loader.sh’ is important, it runs the script in the current shell

Or without loader, which is better :

*/1 * * * * /bin/bash -c ‘export PATH=”$HOME/.rbenv/bin:$PATH” ; eval “$(rbenv init -)”; cd /data/app/; ruby -v’

Leave a Comment