I have a launchctl job I define as such:


When I run script.sh manually, the script works fine, as it uses the currently configured rvm version of ruby. When I run this through launchctl, the system version of Ruby is used, which breaks the script. How can I get this script to run with the right version of ruby available?

2 Answers 2


Change script.sh to set environment variable PATH before it invokes any programs that depend on PATH being set correctly.

  • The only problem is that RVM dynamically points to the current Ruby, which could be anywhere, e.g. ~/.rvm/rubies/ruby-1.9.3-head/bin/ruby. There's no fixed path that can be included.
    – slhck
    Commented Jun 12, 2012 at 19:14

The best way will be to use an rvm "wrapper", which loads the ruby environment and then runs the script. For more info:

$ rvm help wrapper


$ rvm wrapper 2.0.0 hello
$ hello_ruby -e "puts RUBY_VERSION"
$ hello_rake -T
$ which hello_ruby # => /Users/me/.rvm/bin/hello_ruby


And you can use "/Users/me/.rvm/bin/hello_ruby" as the executable in your launchd configs, and the rvm environment will be set up for you.

This is also really nice to do without specifying the exact ruby version so when a patch level comes out, upgrade rvm and your wrappers will point to the newer patched ruby without needing to unload/load the launchd files.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .