Take the 2-minute tour ×
Ask Different is a question and answer site for power users of Apple hardware and software. It's 100% free, no registration required.

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!

share|improve this question
    
If you happen to screw something up, see also: Reset your PATH variable –  koiyu Apr 22 '11 at 10:29
1  
The assignment to PATH (second export) should be with $GRADLE_HOME –  patrix Nov 4 '12 at 21:19
    
@patrix: Thanks, that fixed this problem! –  Jonas Nov 4 '12 at 21:21
add comment

3 Answers

up vote 2 down vote accepted

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!

share|improve this answer
add comment

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

share|improve this answer
2  
Thanks, I used echo 'export PATH=/mypath:$PATH' >> ~/.profile –  Jonas Apr 22 '11 at 8:36
add comment

In addition to the places mentioned by  @RobZolkos, the login shell also looks in /etc/paths and the files inside /etc/paths.d/. One path entry per line in these files.

See /etc/profile and the manual page for path_helper.

share|improve this answer
    
Ok, thanks! but the biggest problem was how to add the path. But I found echo 'export PATH=/mypath:$PATH' >> ~/.profile –  Jonas Apr 22 '11 at 10:52
    
@Jonas: I realized that your problem was solved. My answer was intended for the benefit of future readers, so they can see all the options available to them. –  Harald Hanche-Olsen Apr 22 '11 at 10:56
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.