0

I have a launchctl job I define as such:

<key>ProgramArguments</key>
    <array>
        <string>/bin/sh</string>
        <string>-c</string>
        <string>~/projects/script.sh</string>
    </array>

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?

0

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 Jun 12 '12 at 19:14
0

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

Example:

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

...etc...

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.

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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