UNIX / Linux: Set your PATH Variable using set or export command

by on February 13, 2008 · 10 comments· LAST UPDATED August 12, 2008

in , ,

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



If you would like to be kept up to date with our posts, you can follow us on Twitter, Facebook, Google+, or even by subscribing to our RSS Feed.


{ 10 comments… read them below or add one }

1 Giovanni L. Uson January 27, 2009 at 4:58 am

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

Reply

2 bharath September 30, 2009 at 9:59 am

How to set the CLASSPATH??

Reply

3 anonymous November 3, 2009 at 5:21 pm

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?

Reply

4 Nir December 24, 2010 at 11:12 am

Guys,

how can I remove a path variable??

Reply

5 OnlyOne August 31, 2011 at 10:20 am

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

Reply

6 OnlyOne August 31, 2011 at 10:29 am

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

Reply

7 Sreejith April 27, 2011 at 7:02 am

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

Reply

8 Sreejith April 27, 2011 at 7:04 am

The above one is only for root user

Reply

9 alberto June 6, 2011 at 12:21 am

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)

Reply

10 Sumanth June 11, 2012 at 9:33 am

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

Reply

Leave a Comment

You can use these HTML tags and attributes for your code and commands: <strong> <em> <ol> <li> <u> <ul> <kbd> <blockquote> <pre> <a href="" title="">

Tagged as: , , , , , , , , , , , , , ,

Previous Faq:

Next Faq: