The PATH is an environment variable that tells the shell where to look for the basic executables (commands) you use (such as ping, useradd, etc). Setting a new PATH depends on the shell, not on the Linux or Unix distro.
In this article I will show you how to change the PATH in the most important shells: bash, zsh, ksh.
How to set the PATH in bash, ksh and zsh:
Display the PATH’s value ($PATH):
$ echo $PATH
I will temporary add /home/myscripts in the PATH. After the first logout, the PATH changes will discard: export PATH=$PATH:/new/dir:/new/dir2 . The export command makes a local variable global.
The directories in the PATH are separated one from another with colon (:).
$ export PATH=$PATH:/home/myscripts
You can clear the PATH with export PATH=”” .
How to set the PATH permanently:
To set the PATH changes permanenly, add this line in your user’s shell configuration file:
- in ~/.bashrc for the bash shell
- in ~/.zshrc for the Z shell
- in ~/.kshrc for korn shell
Related reading: How to change the PATH in FreeBSD (for the csh and tcsh shells)