How to set a new PATH in bash, ksh and zsh

How to set a new PATH in bash, ksh and zsh

In this tutorial I will show you, how to set a new PATH in bash, ksh and zsh.

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.

Lets see how to change the PATH in the most important shells: bash, zshksh.

How to set the PATH in bash, ksh and zsh:

Display the PATH’s value ($PATH):

$ echo $PATH
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games

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:

export PATH=$PATH:/home/myscripts

  • 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)

Was this Tutorial helpful? Help others share on Facebook, Twitter, and Google Plus!

 
Enjoyed this video?
How to set a new PATH in bash, ksh and zsh
"No Thanks. Please Close This Box!"