How to add a path to system $PATH for all users's non-login shell for debian
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 the pam_env
module (either in the auth
section or in the session
section); on Debian that should be all of them (at least the ones that provide ways to log in and run commands).
The default path could be set in /etc/profile
like Joe said but also in $HOME/.profile
. I also have plenty of packages i compiled on my own (with the common procedure ./configure --prefix=/opt/<name>
) installed in /opt
. To execute the binaries in /opt/<name>/bin
without any additional effort I added
OPTDIR=/opt
for i in $OPTDIR/* ; do
BINDIR=$i/bin
if [ -d $BINDIR ] ; then
if [ -z $PATH ] ; then
PATH=$BINDIR
else
PATH=$BINDIR:$PATH
fi
fi
done
export PATH
to my $HOME/.profile
which in your case would be /etc/profile
. Now even if i install packages under /opt
in the future i don't have to worry about accessing the related binaries in /opt/.*/bin
since the path is automatically added to $PATH
.
Because the additional software is not necessary stable i prefer $HOME/.profile
over /etc/profile
.
A small remark: /etc/.profile
respectively $HOME/profile
is not executed by your default shell but by dash
. A lightweight variant of bash
which reduces the load during the boot process.