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

by Vivek Gite on February 13, 2008 · 9 comments

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

Featured Articles:

Share this with other sys admins!
Facebook it - Tweet it - Print it -

{ 9 comments… read them below or add one }

1 Giovanni L. Uson January 27, 2009

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

How to set the CLASSPATH??

Reply

3 anonymous November 3, 2009

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

Guys,

how can I remove a path variable??

Reply

5 OnlyOne August 31, 2011

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

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

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

The above one is only for root user

Reply

9 alberto June 6, 2011

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

Leave a Comment

You can use these HTML tags and attributes for your code and commands: <strong> <em> <ol> <li> <u> <ul> <blockquote> <pre> <a href="" title="">
What is 4 + 2 ?
Please leave these two fields as-is:
Solve the simple math so we know that you are a human and not a bot.




Previous post:

Next post: