PATH structure
When you start a terminal session, PATH is built step by step from system settings, user settings, and temporary session changes.
System wide configuration
/etc/environment,
/etc/profile, and
/etc/profile.d/*.
User specific configuration
~/.bash_profile,
~/.profile, and
~/.bashrc.
Session changes
Temporary changes created by commands such as
export PATH=....
System wide configuration
1. /etc/environment
- Purpose: Defines system wide environment variables, including PATH.
-
Common usage: Contains important system paths such
as
/usr/local/binand/usr/sbin. - Third party software: Rarely modified unless the software is installed system wide, for example Java, Docker, or Go.
- Note: It is a simple key value file and does not support shell scripting.
2. /etc/profile
- Purpose: A system wide shell configuration file executed for login shells.
-
Common usage: Sets PATH for global use or sources
scripts from
/etc/profile.d/.
3. /etc/profile.d/
- Purpose: Contains shell scripts used for modular system wide configuration.
-
Common usage: Packages can modify or extend PATH
without editing
/etc/profiledirectly.
User specific configuration
1. ~/.bashrc
- Purpose: Used for non login interactive shells, such as opening a terminal emulator.
- Common usage: User customizations, aliases, functions, and paths for installed tools.
export PATH=$PATH:/home/user/.local/bin
2. ~/.bash_profile or ~/.profile
- Purpose: Used for login shells, for example when logging in through SSH.
-
It can source
~/.bashrcso the settings remain consistent.
if [ -f ~/.bashrc ]; then
source ~/.bashrc
fi
What happens when you modify PATH?
Persistent changes
Created by editing files such as
.bashrc,
.bash_profile, or
/etc/environment.
These changes remain across new terminal sessions.
Temporary changes
Created by running
export PATH=...
in the current terminal. They are lost when that session ends.
Create a short command for software
The original notes describe two ways to make a program easier to launch from the terminal.
Way 1: Create a symbolic link
If you have sudo privilege, create a symbolic link in
/usr/local/bin.
sudo ln -s directoryOfRunningfile /usr/local/bin/filename
# Example
sudo ln -s /usr/local/MATLAB/R2019b/bin/matlab /usr/local/bin/matlab
sudo ln -s /path/to/original/file.txt /path/to/symlink.txt
The notes suggest using
~/.local/bin
instead of /usr/local/bin.
Way 2: Extend PATH
If you do not have sudo privilege, add the software directory to PATH for the current session.
export PATH=$PATH:/usr/local/MATLAB/R2019b/bin
For a persistent user configuration, add the command to
~/.bashrc.
vi ~/.bashrc
Then reload the configuration.
source ~/.bashrc