Ruby – How to tell bundler where the Gemfile is

bundlerruby

I'm trying to run a Ruby script from cron.

The script uses Bundler to manage gem dependencies. Since cron does not run in $PWD I get a 'Could not locate Gemfile' error from Bundler everytime, which makes sense since Gemfile is not in the currrent path when running from cron.

Is there a way to tell Bundler to use a Gemfile not in the current path?

Best Answer

The best thing to do would be to cd into the directory in question in your cron. You could also use the BUNDLE_GEMFILE environment variable to point at the Gemfile. Please let us know if you have any problems with BUNDLE_GEMFILE.