How can I add a path to the PATH environment variable?

I want to add a path to the PATH environment variable?

I have tried with export PATH=/mypath:$PATH and it works. But the next time I start the Terminal, my new path is not int the PATH environment variable any more.

How can I add a path to the PATHenvironment variable? and it should be there also the next time I start the Terminal.


I have problems with this now again, the trick that worked before doesn't seem to work anymore.

I have tried with:

echo 'export GRADLE_HOME=/Users/jonas/gradle-1.2/' >> ~/.profile
echo 'export PATH=GRADLE_HOME/bin:$PATH' >> ~/.profile

to add two environment variables. Then my ~/.profile-file has this content:

export GRADLE_HOME=/Users/jonas/gradle-1.2/
export PATH=GRADLE_HOME/bin:$PATH

But when I start a new Terminal window and type gradle (the command I added to PATH), I get a message that the command doesn't exists. If I run the command from /Users/jonas/gradle-1.2/bin it works fine!


echo 'export PATH=/my/path:$PATH' >> ~/.bash_profile should do the trick!

If you used echo 'export PATH=/my/path:$PATH' > ~/.bash_profile, or any such variation, you would be overwriting the contents of your profile!


OSX reads the following files in order when a terminal opens :

/etc/profile
~/.bash_profile
~/.bash_login   
~/.profile     

So place your path addition into one of these. I normally put additions into ~/.bash_profile