Q. How do I add new path to PATH variable under Linux and UNIX operating system?
A. The syntax for setting path under UNIX / Linux dependent on which shell you are using. BASH / SH shell uses following syntax:
export PATH=$PATH:/path/to/dir1:/path/to/dir2
For tcsh or csh, shell enter:
set PATH = ($PATH /path/to/dir1 /path/to/dir2)
You can type above command at the terminal or add it to your .bashrc (for BASH/sh shell) or .cshrc (for chs / tcsh shell) so that PATH can be set each time you login into box. For example add /usr/local/bin to your path under BASH, enter:
export PATH=$PATH:/usr/local/bin
Or add as follows to your .bashrc file:
echo 'export PATH=$PATH:/usr/local/bin' >> ~/.bashrc
If you are using CSH / TCSH, enter:
echo 'set PATH = ($PATH /usr/local/bin /scripts/admin)' >> ~/.cshrc
To display path settings, enter:
$ echo $PATH
- 30 Handy Bash Shell Aliases For Linux / Unix / Mac OS X
- Top 30 Nmap Command Examples For Sys/Network Admins
- 25 PHP Security Best Practices For Sys Admins
- 20 Linux System Monitoring Tools Every SysAdmin Should Know
- 20 Linux Server Hardening Security Tips
- Linux: 20 Iptables Examples For New SysAdmins
- Top 20 OpenSSH Server Best Security Practices
- Top 20 Nginx WebServer Best Security Practices
- 20 Examples: Make Sure Unix / Linux Configuration Files Are Free From Syntax Errors
- 15 Greatest Open Source Terminal Applications Of 2012

- My 10 UNIX Command Line Mistakes
- Top 10 Open Source Web-Based Project Management Software
- Top 5 Email Client For Linux, Mac OS X, and Windows Users
- The Novice Guide To Buying A Linux Laptop



![Linux: Change the PATH [ Add New Directory ]](http://s0.cyberciti.org/images/rp/1/13.jpg)







{ 10 comments… read them below or add one }
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