PATH can be a pain, but there are some basics:
- $PATH before or after (before)
- Is EXPORT needed, or not (not)
- Where is PATH set
- All apps+shells
- All shells
/etc/profilefor all users (or a separate file under /etc/profile.d/ if using pacman)
- Bash shell
- Fish shell
- All apps+shells
To Export or Not
Export is useful in a script, when say making a copy of the path, changing the path, exporting (updating the live path), executing some other commands, and then changing the path back and re-exporting (see example here). However, export doesn't work the same way in all shells.
However, simply having permanent Export commands in a standard config file makes no sense, though it is common practice.
Where to put the PATH variable
bash as a login shell doesn't parse
Therefore, since it is likely there are some things are (or will be) in
~/.bash_profile, that would be the most likely place for PATH to be (for Bash).
~/.bashrc vs. ~/.bash_profile vs. ~/.profile
~/.bashrconly works for shells that are both non-login and interactive, though this is largely ignored as most
~/.profileis the old
/bin/shlogin script, and Bash will read it to be backward compatible
~/.bashrcis generally good, for odd/unknown reasons it fails to load at times, especially second and subsequent logins. Therefore,
~/.profilecan be a better choice (or
If a single PATH should be the same for every shell, and even every app, then a core environmental variable should be the place where the PATH would reside.
Previous to all ./profiles is the use of
/etc/environment which is global.
Bash ~/.bashrc Example
# .bashrc # User specific aliases and functions alias rm='rm -i' alias cp='cp -i' alias mv='mv -i' # Source global definitions if [ -f /etc/bashrc ]; then . /etc/bashrc fi PATH=$PATH:/usr/local/bin export PATH
Fish ~/.config/fish/config.fish Example
set PATH $PATH /usr/local/bin export PATH function ll ls -lh $argv end
See also: Fish Shell $PATH
Reload the Config file (while preserving the session)