The PATH environment variable in Bash determines the directories the shell searches for executable files. It is a colon-separated list of absolute paths that lets the system locate commands quickly. Proper configuration of PATH avoids command-not-found errors and streamlines workflows.
Using PATH allows administrators and developers to add custom directories containing scripts, binaries, or tools for convenient execution. Modifying this variable can be done on a per-session basis or made persistent across logins. It is critical to ensure directories in the PATH are valid and secure.
Incorrect PATH settings may cause scripts and applications to fail unexpectedly. Security risks arise if untrusted directories appear in the PATH, so meticulous configuration is essential. By adjusting the PATH thoughtfully, it is possible to maintain clean, stable, and organized environments.
Steps to set PATH environment variable temporarily:
This method updates the PATH for the current session only, and it reverts to the default after closing the shell. It is suited for testing new paths or running a command once without making permanent changes. Temporary changes are quick to apply but do not persist after logout or reboot.
- Check your current PATH variable by running echo $PATH.
$ echo $PATH /usr/local/bin:/usr/bin:/bin
- Add a new directory to the PATH using the export command.
$ export PATH="/opt/newdirectory:$PATH"
- Verify the updated PATH by echoing it again.
$ echo $PATH /opt/newdirectory:/usr/local/bin:/usr/bin:/bin
These changes last only for the current session.
Steps to set PATH environment variable permanently:
This method ensures the changes remain effective across new shell sessions and system reboots. It involves editing a shell configuration file such as .bashrc or .profile. Permanent changes streamline a user’s environment for ongoing tasks.
- Open your home directory’s .bashrc file in a text editor.
$ nano ~/.bashrc
- Append the export command to the file.
export PATH="/opt/newdirectory:$PATH"
Ensure the directory opt/newdirectory exists before adding it.
- Save and close the file.
- Reload .bashrc to apply the changes immediately.
$ source ~/.bashrc
Use source or reopen the terminal to load the new environment.
- Confirm the PATH by running echo $PATH again.
$ echo $PATH /opt/newdirectory:/usr/local/bin:/usr/bin:/bin

Mohd Shakir Zakaria is a cloud architect with deep roots in software development and open-source advocacy. Certified in AWS, Red Hat, VMware, ITIL, and Linux, he specializes in designing and managing robust cloud and on-premises infrastructures.
Comment anonymously. Login not required.