HOWTO: Make system-wide RVM installations work with cron, monit, delayed_job, and passenger

System-wide RVM installations are recommended for production deployments, but because /usr/bin/ruby is no longer the “correct” ruby, you need to tell all your moving parts about RVM.

Before installing ruby

Make sure you’ve installed the development libraries that ruby and all of your gems need to work. For AdGrok, that amounts to:

Finish the installation

After you install RVM, look at your /etc/profile. If you already have this section:

you just need to copy the following into a new file, /etc/profile.d/rvm.sh:

I originally had this in /etc/bash.bashrc, but that broke the “bash -l” solution below (because “PS1″ wasn’t defined).

Fix rails runner crontabs

Cron’s default shell, /bin/sh, doesn’t load the “interactive shell” configuration, so RVM won’t be available.

RVM comes with a “rvm-shell” wrapper script to fix this issue. Edit your crontab and change the SHELL. Here’s my whole /etc/cron.d/example.cron:

Fix monit/delayed_job

The author of RVM suggested you could omit the “as uid … and gid …” and use a /bin/su prefix to load RVM, but I couldn’t get it to work for me. I had to use the bash -l -c method, just like in my crontab:

Fix Phusion Passenger

When you installed passenger, you specified a “PassengerRuby” value. Change that from /usr/bin/ruby1.8 (or whatever), to RVM’s ruby. In my case, it was

Tagged with: , , , , , ,
Posted in Technical HOWTOs
  • JS

    Thank you!  I was just running into this issue the other day with Monit.  Very helpful.

  • http://jaylevitt.myopenid.com/ Jay Levitt

    And then there’s PassengerPreStart, which expects ruby to be in $PATH.  On Ubuntu, you can solve that by adding “export PATH=/usr/local/rvm/bin:$PATH” to /etc/apache2/envvars.

  • Eric G

    Thanks. Re. monit using rvm-shell, what I got to work needed the ruby/gemset string as well like
    /usr/local/bin/rvm-shell ’1.9.3′ -c  ‘ … ‘