How can I edit the $PATH on linux?

I am using ubuntu 9.04 I need to add some folder to my $PATH. I know how to read the path:

echo $PATH

I want to be able to edit it and add 2 other paths.

Thanks


Solution 1:

To permanently store your path, you have a few options.

I suggest you read the Ubuntu community wiki on Environment Variables but the short answer is the best place is ~/.profile for your per-user PATH setting or /etc/profile for global settings.

Do something like export PATH=$PATH:/your/new/path/here

Solution 2:

PATH=$PATH:newPath1:newPAth2
export PATH

Solution 3:

You can also put this in the global environment:

sudo emacs /etc/environment

Append to the entries already in your path

PATH="/path/to/file:/other/paths"

Reload the environment

source /etc/environment

Solution 4:

It has already been answered on how to do that, but I'd like to give you a little tip. Here is whatI do:

I have a directory called .bash.d in my $HOME and within that I keep a set of shell scripts that do stuff to my environment (for instance setup maven correctly, modify the path, set my prompt etc.). I keep this under version control by using git, which makes it easy to go back to a working version of your env, if you screw something up badly. To get all the modifications, I simply source all files in that dir at the end of my .bashrc like this:

for i in $HOME/.bash.d/*; do source $i; done
unset i

This gives you a very flexible environment that you can easily modify and restore + you are able to export it to other machines just by using git.

Solution 5:

echo PATH=$PATH:path1:path2 > tmp

Edit the file tmp with your favourite text editor so the value of PATH is exactly what you want

. ./tmp