Make /etc/profile
source /etc/bash.bashrc
by adding [ -f /etc/bash.bashrc ] && . /etc/bash.bashrc
to the end of /etc/profile
, then add your path changes to /etc/bash.bashrc
with PATH=$PATH:/some/other/path
Add a file with the value you want the PATH
to have in /etc/profile.d
. These files are setup to be sourced by shells such as Bash, Csh Zsh, or tcsh.
Example
We needed to have the following value added to our PATH.
/usr/local/share/bin
So we created a file, /etc/profile.d/ourstuff.sh
, with the following line in it:
export PATH=/usr/local/share/bin:$PATH
Files with the extension .sh
are sourced by shells such as Bash and Zsh. Files with the extension .csh
are sourced by Csh and tcsh.
EDIT #1 - Follow-up
OP asked the following follow-up question.
Yes, but what about cron jobs? Is there a way to get the path even there? cron doesn't seem to call /etc/profile or /etc/bashrc.
To which I responded:
Correct it doesn't nor will it. You need to set the SHELL=/bin/bash
in cron to override the default shell (typically /bin/sh
). Also you can set the this for user crons, BASH_ENV="$HOME/.bashrc", and this for system crons, BASH_ENV="/root/.bashrc"
. Would be one way around this.
I would highly suggest that you not do this. Let the scripts that need a specific environment, set it up themselves. Don't try to solve every problem at the global level!
Best Answer
On Debian and other systems that use PAM (which is most of them nowadays), you can set environment variables (including
PATH
) in/etc/environment
. This will work for any login method that uses thepam_env
module (either in theauth
section or in thesession
section); on Debian that should be all of them (at least the ones that provide ways to log in and run commands).