Where can I add to my path that it will be available for all users, all shells, all the time. In this case I want /opt/grails/bin to always be available even when being run as tomcat user from jenkins.

There are 6+ files that you can stick this in, but I have yet in my years of being a software dev who occasionally handles Linux sysadmin tasks to find a clear explanation of where you do export PATH=$PATH:/opt/grails/bin
and have it available to every user, every type of shell, all the fXXXing time.

I'm on Ubuntu 10.10 if that matters.


1 Answer 1


Usually it's /etc/profile (readed by bash, dash, ksh, and its "sh" modes).

For system users, you can declare single variables, at /etc/environment. It's not a good practice but it works (I used to use it for JAVA_HOME etc).

The main issue with PATH is that it should be different for system users and for system superusers. So instead of a single variable in /etc/environment, I would try patching /etc/profile (the debian/ubuntu way, is to put a script into /etc/profile.d/).

One line exports is a bashism, check the first lines of /etc/profile for portable syntax (to work with /bin/sh, dash, etc).

This solution shouldn't work for csh, tcsh, and the like shells, but should for bourne like shells.

On ubuntu, you can research about PAM, that has some things to say about environment and PATH, but it's more about login than about shell initialization.

Update: To go for PAM (su, sudo, etc) try: /etc/login.defs maybe the single file that you need.

  • Portability to non-bash shells not important. The problem with /etc/profile is that it's not picked up when you do # su -c "$GRAILS_HOME/bin/grails" tomcat, and it won't run. Adding it to /etc/environment works, but that is not picked up by interactive login shells, requiring me to add it to both which seems clunky as hell. Regarding the "$PATH should be different" comment I of course understand why some things should only be available to root, but is there not ONE SINGLE FILE where I can say, "hey system this is where $GRAILS_HOME lives and don't forget it."
    – orange80
    Apr 17, 2011 at 18:21
  • According to manpage, su resets the PATH. Look at the answer update, hope it helps.
    – poisonbit
    Apr 17, 2011 at 18:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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