Rails cron whenever, bundle: command not found

Solution 1:

You can also ensure your PATH ends up in the crontab, by putting the following at the top of the schedule.rb file:

env :PATH, ENV['PATH']

https://groups.google.com/forum/#!msg/whenever-gem/yRLt3f2jrfU/Exu3xfCo8DAJ

If above solution don't work for you, try:

env :GEM_PATH, ENV['GEM_PATH']

Solution 2:

In my case I just ran :

rvm env --path -- ruby-version[@gemset-name]

Referring to cron job setup doc

Added new source line to the command for ruby path before bundle command in the crontab -e

source /usr/local/rvm/environments/ruby-1.9.3-p392;

Now the commands like as below:

Before:

0 4 * * * cd /home/current && bundle exec rake my_rake RAILS_ENV=production

After:

0 4 * * * cd /home/current && source /usr/local/rvm/environments/ruby-1.9.3-p392; bundle exec rake my_rake RAILS_ENV=production

Cheers!!!

Solution 3:

After so many try outs the following seems to work

Type the following from terminal

  1. Type crontab -e This opens the crontab for editing. You will see two lines as below:

    # cron clears out environment variables, but Rubber.root/script/rubber uses
    # "rvm do default" to run, so no longer any need to setup ruby env vars here,
    # all we need is PATH
    PATH=/<path to bundle>/bundle/ruby/1.9.1/bin:/usr/local/rvm/gems
    

    AND

    # Begin Whenever generated tasks for: /mnt/wamjoke-production/releases/20120912$
    PATH=/<path to bundle>/shared/bundle/ruby/1.9.1/bin:/usr/local/rvm/gems
    
  2. Comment out both lines beginning with PATH.

Do the above step whenever you run "bundle exec whenever" command. And it works.

No idea why PATH is misleading the environment.

Solution 4:

I hate this problem - I've spent hours trying to solve it too.

What works for me is to add

RAILS_ENV=production; source /usr/local/rvm/scripts/rvm;

before the bundle command.