Crontab + Ruby on Rails: /usr/bin/env: ruby: No such file or directory

6,700

Wherever ruby is, it's not in the $PATH of cron. Find the actual location of ruby by running type -a. Then add it's path to the $PATH environment variable in your crontab.

Example, if you find type -a shows that the path to ruby is /usr/local/bin/ruby (and judging by your path to rake it likely is), your crontab should look like this:

PATH=$PATH:/usr/local/bin
*/5 * * * * RAILS_ENV=production /usr/local/bin/rake -f /usr/local/www/mysite-web-production/current/Rakefile my_site:export_products >> /var/log/export_feed.log 3>&1

Or possibly:

*/5 * * * * RAILS_ENV=production PATH=$PATH:/usr/local/bin /usr/local/bin/rake -f /usr/local/www/mysite-web-production/current/Rakefile my_site:export_products >> /var/log/export_feed.log 3>&1

Either should work.

Share:
6,700

Related videos on Youtube

bigpotato
Author by

bigpotato

Updated on September 18, 2022

Comments

  • bigpotato
    bigpotato over 1 year

    I have a ruby on rails app and I need to schedule a crontab for a rake task.

    */5 * * * * RAILS_ENV=production /usr/local/bin/rake -f /usr/local/www/mysite-web-production/current/Rakefile my_site:export_products >> /var/log/export_feed.log 3>&1
    

    However, it's not working (it works when I do it manually, but not as a crontab) and it's showing me /usr/bin/env: ruby: No such file or directory. I'm not using RVM. I'm using ruby 1.9.3 and rails 3 on Linux.