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.

In this article I will show you 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)

Share and Enjoy

  • Twitter
  • Facebook
  • Google Plus
  • Email
  • RSS
Tagged with: , , , , , , , ,
Posted in The Linux and Unix Articles!

Leave a Reply

Your email address will not be published. Required fields are marked *

*