This question already has an answer here:

I have cron running for rails application on EC2 instance, but it fails with error -

/bin/bash: bundle: command not found

if I run bundle command with ubuntu user or sudo user that works. I have added cron using crontab -e command.

Some Troubleshooting I did (displays same result with sudo as well) -

> which ruby

> which bundle

But if add these command as which ruby and which bundle in crontab and output it over logs, it shows -

Cron has -

* * * * * /bin/bash -l -c 'which ruby >> /home/ubuntu/logs/cron.log 2>&1'
* * * * * /bin/bash -l -c 'which bundle >> /home/ubuntu/logs/cron.log 2>&1'

Output -

/bin/bash: bundle: command not found

so basically my cron is taking wrong ruby from system, what should I do to correct that ? I want to take ruby from my /usr/local/bin/ruby and then it can find bundle as well.

Thanks !!

marked as duplicate by Iain, Jenny D, Cristian Ciupitu, Tom O'Connor May 13 '14 at 14:13

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • 1
    This isn't really a crontab problem, more a $PATH problem. – Tom O'Connor May 13 '14 at 14:11

You can specify the full path, as thince notes.

You should also be able to set the PATH at the top of your crontab:

* * * * * ruby /home/ubuntu/scripts/ruby.rb >> /home/ubuntu/logs/cron.log 2>&1'
* * * * * bundle exec unicorn >> /home/ubuntu/logs/cron.log 2>&1'

Actually, I see that you have ruby installed in /usr/bin and /usr/local/bin. In that case, if you want a specific ruby, fully specify the path. With the cron as written above, because of the PATH order, you will execute /usr/bin/ruby and not /usr/local/bin/ruby.

  • Thanks a lot @cjc, I added this - PATH=$PATH:/usr/local/bin it worked smoothly. Thanks !! – rtdp Dec 9 '11 at 21:23

Not the answer you're looking for? Browse other questions tagged or ask your own question.