I have a server with nginx and Passenger serving a Ruby on Rails app. It uses Bundler.

Somewhere in this stack, the $PATH gets set to /var/www/APPNAME/shared/bundle/ruby/1.8/bin/. This directory contains, indeed, executable gems.

But I need my application to also have /usr/bin available in its $PATH. More specific: I need it to be able to run idendtify, convert and mogrify; imagemagick commands.

For now, I have symlinked these imagemagick binaries from /var/www/APPNAME/shared/bundle/ruby/1.8/bin/:

ls /var/www/APPNAME/shared/bundle/ruby/1.8/bin/ -ahl
lrwxrwxrwx 1 root root   16 May  8 16:22 convert -> /usr/bin/convert
-rwxr-xr-x 1 ber  root  379 Jan 11 08:58 erubis

It's more of a quick hack than an actual solution, though.

How can I assign extra directories to $PATH? And where should I do that? Passenger, nginx, the Rails app?


The ruby options are a good way to do this. Specify that the $LOAD_PATH have /usr/bin.

-Idirectory     specify $LOAD_PATH directory (may be used more than once)

It is what it is there for, after all.

Another thing you can do is push the directory onto the $: global psuedo-variable.


This would fit wherever you have your environment customization in your application.

I would probably do this for the Rails Application itself, as that is where you are concerned about it. It is what you have control over.

  • Thanks! I have access to the entire stack (as I have installed it myself), though I am most familiar with the Ruby app. There are more apps running here, though, so I'd prefer to configure this as lowin the stack as possible: nginx or passenger. And not (like I have now) hacked into the Bundle :). – berkes May 9 '13 at 8:44
  • When I said it is what you have control over, I was talking about as opposed to the gems you use. Gems get updated, and may overwrite your setting. The application that you write you have control over, and this type of change won't get overwritten. That was what I mean. – vgoff May 9 '13 at 17:05
  • I would probably look at adding the path to the .bashrc file then. – vgoff May 9 '13 at 18:31
  • .bashrc? the www-data user has no shell, not? Or am I missing something? – berkes May 10 '13 at 8:41
  • 1
    www-data:x:33:33:www-data:/var/www:/bin/sh on my system, and has /bin/sh as the shell for doing its work... – vgoff May 10 '13 at 19:39

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.