Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I was trying to add something to $PATH and it went totally wrong. I now can't run any commands such as ls. I've looked at this answer (http://apple.stackexchange.com/questions/11745/reset-your-path-variable) and used the following lines:

PATH=/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/X11/bin

PATH=$PATH:~/bin

These lines fix the problem temorarily; however, when I restart terminal it seems to forget these changes.

How do I permanently reset my $PATH?

I'm running the most recent version of Mountain Lion.

Thanks

share|improve this question
    
Where did you try adding something to your $PATH? Which file did you change? –  slhck Jan 18 '13 at 21:57
    
I think it was .bash_profile but it may have been .profile...I'm very inexperienced with terminal –  Nosrettap Jan 18 '13 at 21:58
1  
Then just open these files and remove whatever line begins with PATH= or export PATH=. –  Aluísio A. S. G. Jan 18 '13 at 21:59
    
It was either .bashrc or .profile or .bash_profile. Check all three. –  terdon Jan 18 '13 at 22:00
    
also asked on askdifferent –  glenn jackman Jan 19 '13 at 1:01

2 Answers 2

up vote 2 down vote accepted

You obviously have a malformatted line somewhere in one of your shell configuration files that are read when the Terminal starts Bash. This is either .profile or .bash_profile, depending on which you used. In OS X, .bashrc isn't read unless you've explicitly sourced it from one of these other files.

To be able to use the commands without setting a $PATH, simply call them by their full location.

If you know that there's nothing else in the files you need, delete them:

/bin/rm ~/.bash_profile
/bin/rm ~/.profile

If not, open them in TextEdit, for example, and remove the offending lines with PATH=:

/usr/bin/open -a TextEdit ~/.bash_profile
/usr/bin/open -a TextEdit ~/.profile

If you'd like to use a command line editor, you can do that as well:

/usr/bin/vim ~/.bash_profile
/usr/bin/nano ~/.bash_profile
# et cetera
share|improve this answer
    
Thank you so much!/bin/rm ~/.bash_profile worked! –  Nosrettap Jan 18 '13 at 22:02
    
You're welcome! In the future, if you're trying out things in your PATH, you could always run a second Terminal tab in the background in case something goes wrong. –  slhck Jan 18 '13 at 22:40

This was also asked on apple stackexchange and the accepted answer here is dangerous.

Rather than just removing the .bash_profile better to do as the commenters suggest and fix the PATH definition. The problem is that you defined it from "scratch" first, overwriting all previous definitions (including where to find ls, and others).

You define the path in .bash_profile by setting a new variable equal to the old one (read with $PATH) plus what you want to add:

export PATH=$PATH:$HOME/myspecialfolder:$HOME/bin

Note that you can't have any spaces on either side of the equal sign. I am also leaving out {}, which you might need if there are spaces in your folder names.

share|improve this answer
    
I did say "If you know that there's nothing else in the files you need, delete them". You might want to read through it again, because I mentioned a few ways of editing the file to remove the wrong statements. –  slhck Aug 28 '13 at 21:56
    
Yes, I know you caution against it, but that was the take-home that the OP posted on the other site: "Solved it: rm ~/.bash_profile". I am just trying to point out the source of their original problem in the PATH definition, before recommending amputation ;^) –  beroe Aug 28 '13 at 23:02
    
@Slhck I see what you were trying to do, and re-added an up vote, but I think a more general fix would be to define an emergency PATH in the terminal as PATH=/bin:/usr/bin –  beroe Aug 29 '13 at 11:33
    
Yes, that would work as an emergency solution, but you'd still need to do something with the profile to fix it. I think the OP knows that the source of the problem was the faulty definition, and since they didn't use the .bash_profile for anything else (as they admitted they were inexperienced with navigating the terminal), I recommended deletion. –  slhck Aug 29 '13 at 11:37

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.