I started looking into files such as:
- /etc/profile
- ~/.bash_profile
- etc.
in order to locate where environment variables were defined. Unfortunately, I couldn’t locate the $PATH variable. I am using Bash.
I started looking into files such as:
in order to locate where environment variables were defined. Unfortunately, I couldn’t locate the $PATH variable. I am using Bash.
2
Answers
The initial
PATH
environment variable is inherited from … whatever launched the shell. For example commands likesudo
,sshd
, whatever creates your shall after a desktop login.There also appears to be a
PATH
that is hardwired into thebash
binary for cases where an initialPATH
is not inherited. (Look at the output fromstrings /bin/bash
.)Then various shell initialization scripts get a go at setting or updating
PATH
. For example, on Ubuntu thePATH
variable is updated by/etc/profile.d/apps-bin-path.sh
… which is run by/etc/profile
.You should not worry (or even ask) where
PATH
is set, since you should not be trusting a random distro to put the right directories in the right sequence.Instead, you set the
PATH
you need in your shell’s profile. That’s it.As a starting point, POSIX mandates that
getconf PATH
returns the system’s defaultPATH
. If you have a$HOME/bin
and there’s a/usr/local/bin
, then you add them.Here’s what this looks like on my machine:
With this setup, it’s easy to adapt the sequence. Maybe you don’t like the ancient vim in
/usr/bin/vi
? Compile it yourself and move/usr/local/bin
to the front.