Whenever gem, cronjobs and chruby

chruby: not found

If your cron log says something like this:

/bin/sh: 1: chruby: not found

It’s very likely that cron can’t find chruby1. Since cron has a very stripped down environment, you have to add the follow lines at the top of your crontab (su/login as the user that is running your cronjobs and edit your crontab with crontab -e):


Whenever and chruby

I’m using the whenever gem to manage my cronjobs. In some cases you need to call chruby-exec inside those cronjobs. If you’re using whenevers runnner method, you can add chruby-exec like so2:

# config/schedule.rb
job_type :runner,  "cd :path && /usr/local/bin/chruby-exec ruby-2.3.0 -- bin/rails runner -e :environment ':task' :output"

This will convert to:

0 1 * * * /bin/bash -l -c 'cd /your/webserver/path/ && /usr/local/bin/chruby-exec ruby-2.3.0 -- bin/rails runner -e production '\''SomeService::SomeClass.some_method'\'''
  1. Here is an related GitHub issue 

  2. I’m using Debian Linux and run Cronjobs as a user called “deploy”. So you might have to change those values accordingly to match the ones of your system. 

Feedback? Du erreichst mich via Mail oder Mastodon.

Wenn du meinen Blog abonnieren möchtest, findest du hier meinen RSS Feed.