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
/etc/environment - All shells
/etc/profile for all users (or a separate file under /etc/profile.d/ if using pacman)
- Bash shell
- Fish shell
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
~/.bash_loginexists. -Source Also, note that
~/.bash_profileis not run if there is a non-login shell invocation, which means
~/.bashrcis really where you want 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.
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 # Source global definitions if [ -f /etc/bashrc ]; then . /etc/bashrc fi # User specific aliases and functions alias rm='rm -i' alias cp='cp -i' alias mv='mv -i' alias lx='ls -la --color=auto' alias rx='rm -rf' PATH=$PATH:$HOME/bin:~/.local/bin:/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)