The PATH is an environment variable. It is a colon delimited list of directories that your shell searches through when you enter a command. All executables are kept in different directories on the Linux and Unix like operating systems.
Finding out your current path
To find out what your current path setting, type the following command at shell prompt. Open the Terminal and then enter:
echo "$PATH" |
OR
printf "%s\n" "$PATH" |
Sample outputs:
/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/opt/X11/bin:/usr/local/sbin/modemZapp:/Users/vivek/gcutil-1.8.4
How do I modify my path?
To modify your path edit $PATH variable as per your shell. The syntax for setting path under UNIX / Linux dependent upon your login shell.
Bash, Sh, Ksh shell syntax to modify $PATH
If you are using bash, sh, or ksh, at the shell prompt, type:
## please note 'PATH' is CASE sensitivity and must be in UPPERCASE ## export PATH=$PATH:/path/to/dir1 export PATH=$PATH:/path/to/dir1:/path/to/dir2 |
OR
## please note 'PATH' is CASE sensitivity and must be in UPPERCASE ## PATH=$PATH:/path/to/dir1; export PATH |
Please feel free to replace /path/to/dir1 with the directory you want the shell to search.
Tcsh or csh shell syntax to modify $PATH
If you are using tcsh or csh, shell enter:
## please note 'path' is case sensitivity and must be in lowercase ## set path = ($path /path/to/dir1) set path = ($path /path/to/dir1 /path/to/dir2) |
OR
## please note 'PATH' is CASE sensitivity and must be in UPPERCASE ## setenv PATH $PATH:/path/to/dir1 setenv PATH $PATH:/path/to/dir1:/path/to/dir2 |
Please feel free to replace /path/to/dir1 with the directory you want the shell to search.
Examples
In this example add /usr/local/bin to your path under BASH/ksh/sh shell, enter:
export PATH=$PATH:/usr/local/bin |
OR
PATH=$PATH:/usr/local/bin; export PATH |
To make these changes permanent, add the commands described above to the end of your ~/.profile file for sh and ksh shell, or ~/.bash_profile file for bash shell:
## BASH SHELL ## echo 'export PATH=$PATH:/usr/local/bin' >> ~/.bash_profile |
KSH/sh shell user try:
## KSH / SH SHELL ## echo 'export PATH=$PATH:/usr/local/bin' >> ~/.profile |
In this final example add /usr/local/bin/ and /scripts/admin/ to your path under csh / tcsh shell, enter:
set path = ($path /usr/local/bin /scripts/admin) |
OR
setenv PATH $PATH:/usr/local/bin:/scripts/admin |
To make these changes permanent, add the commands described above to the end of your ~/.cshrc file:
echo 'set path = ($path /usr/local/bin /scripts/admin)' >> ~/.cshrc |
OR
echo 'setenv PATH $PATH:/usr/local/bin:/scripts/admin' >> ~/.cshrc |
To verify new path settings, enter:
$ echo $PATH
See also
- Man pages – bash(1),ksh(1),csh(1),tcsh(1)



21 comment
Hello,
I am a newbie on Linux.
I would like to ask if I can include an environment variable (e.g. ARCHIVES) that points to a directory (e.g. EXPORT ARCHIVES=/some/path/directory) to the .bash_profile, so that I dont do exporting all the time, everytime I need to use the directory?
regards,
Giovanni
How to set the CLASSPATH??
Or add as follows to your .bashrc file:
“echo ‘export PATH=$PATH:/usr/local/bin’ >> ~/.bashrc”
Isn’t echo ” ‘PATH=$PATH:/usr/local/bin’ >> ~/.bashrc ” a better idea?
Guys,
how can I remove a path variable??
Hi,
To remove a path, go to”File System”. Open
/etc folder and edit (that is, remove )the path from the ‘environment’ text file. You can edit using the sudo command. Following are the commands.
cd ~
cd etc
sudo gedit environment
After removing the path from the “environment” file, save and restart the machine
Hi,
There was one mistake. It is “cd /”, not “cd ~”
To remove a path, go toâ€File Systemâ€. Open
/etc folder and edit (that is, remove )the path from the ‘environment’ text file. You can edit using the sudo command. Following are the commands.
cd /
cd etc
sudo gedit environment
After removing the path from the “environment†file, save and restart the machine
To add a PATH for any user with sh or bash shell permanantly use the following steps.
1. Create a new file .profile in root(/) directory.
2. Add the following lines into it
PATH= path to enter
export PATH
3.save the file
4.exit and login to server again
5.check using echo $PATH
IT will work. Please let me know if tou have any queries on this !!!
Sreejith
The above one is only for root user
When I run my program I get this result:
terminate called after throwing an instance of ‘std::logic_error’
what(): basic_string::_S_construct NULL not valid
Aborted
Is this a result of having the wrong environment variable on my path or what. The program compiles without any errors. This is happening on Ubuntu (Linux, OS 10.0)
Hi ,
Could any one explain me about the functionality of command in shell script
set -xv
. /opt/app/etl/bin/profile.ksh
. `dirname $0`/env.cfg
Hi Sumanth,
Print input commands and their arguments as they are executed –> when you use set -xv
Hi there, thanks fo the article!
FYI, I just tried the syntax above for a tcsh but it didn’t work.
This works:
setenv PATH ${PATH}:${HOME}/bin:.(Include this line directly in your .cshrc file. This example adds a dir called ~/bin and your current dir to the previously existing PATH)
(Or, if you don’t want to open and edit your ~/.cshrc file, type this in a teminal:)
echo 'setenv PATH ${PATH}:${HOME}/bin:.' >> ~/.cshrcHi,
Thanks for the heads up. The faq has been updated with correct syntax. FYI, the syntax setenv PATH ${PATH}:${HOME}/bin:. can be updated using the following syntax too:
Appreciate your post.
it helps me lots thanks………….
Hi :
I am new to linux.
May I ask how to convert this bash to tcsh?
Best Regards,
McGrady
Useful.. Thanks
why would this code be on my computer in a install file with along with macports pubkey and several other files?????
# $Id: setupenv.bash.in 99822 2012-11-18 11:20:14Z raimue@macports.org $ function export_path() { local binpath="/opt/local/bin" local sbinpath="/opt/local/sbin" local IFS=":" local p for p in $PATH; do if [ "$p" == "$binpath" ]; then binpath="" elif [ "$p" == "$sbinpath" ]; then sbinpath="" fi done if [ -n "$binpath" ]; then binpath+=":" fi if [ -n "$sbinpath" ]; then sbinpath+=":" fi export PATH="${binpath}${sbinpath}${PATH}" } function export_manpath() { local mpath="/opt/local/share/man" local IFS=":" local p if [ -z "$MANPATH" ]; then return fi for p in $MANPATH; do if [ "$p" == "$mpath" ]; then mpath="" fi done if [ -n "$mpath" ]; then mpath+=":" fi export MANPATH="${mpath}${MANPATH}" } function export_display() { if [ -z "$DISPLAY" ]; then export DISPLAY=":0.0" fi } export_path export_manpath export_display # Remove defined functions to prevent them from cluttering the shell, # but they are needed to restrict variables to the local scope unset export_path unset export_manpath unset export_displaySET doesn’t seem to do anything.
PATH as a variable name is case sensitive by me, but in this tut, this gets ignored.
Very bad. Didn’t helped me at all.
hello,
by mistake i changed defaults PATH ,how can i get default PATH from command line
i can’t even vi that hiden files
please help
Thanks
I have a machine that is running on kernel 2.6.32-504.16.2.el6.x86_64, I want to build a custom kernel using the same kernel on the same machine, but when I run make menuconfig, I get the following error
*** Unable to find the ncurses libraries or the
*** required header files.
*** ‘make menuconfig’ requires the ncurses libraries.
***
*** Install ncurses (ncurses-devel) and try again.
***
make[1]: *** [scripts/kconfig/dochecklxdialog] Error 1
make: *** [menuconfig] Error 2
I have the ncurses installed already in /lib64 and modified my PATH to point to /lib64, but I still get the same error, it looks like that it can not be found. does anyone have an idea why this is not working?
Install “ncurses-devel” package and try again.