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 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 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.

share|improve this question
4  
Fixed it: /bin/rm ~/.bash_profile –  Nosrettap Jan 18 '13 at 22:03
2  
Good question. You could always put your fix in an answer. –  bassplayer7 Jan 18 '13 at 22:43
    
Also asked on superuser –  glenn jackman Jan 19 '13 at 1:00
1  
Realizing you already fixed your problem, users with a similar issue might also find help at /etc/paths –  BigDave Jan 21 '13 at 12:37

4 Answers 4

The suggested answer of removing .bash_profile is not a good idea in general. There are other things that can be set in that file besides PATH definitions.

If you want to undo the effects of your experimentation, just remove or comment out that PATH line with a #.

You don't want to edit the PATH from scratch, but append to it, as you did with your second line. The preferred method of adding something to your path would be:

export PATH=$PATH:$HOME/bin

EDIT Since your PATH is messed up, you don't have access to the usual commands to make these changes. As a temporary fix, you can define a new minimal path in a Terminal window (not in your .bash_profile) by typing:

PATH=/bin:/usr/bin

This will temporarily give you access to nano ls mv vi cat and rm -- the basic tools to check and edit your .bash_profile and fix your problem...

Repeat, do not put this PATH definition anywhere except for the duration of the session while you make your fixes.

share|improve this answer

Remove the your bash profile to restore the default $PATH. Enter the following command into Terminal.app:

/bin/rm ~/.bash_profile

The change will take place with the next shell or terminal session.

share|improve this answer
    
Answering, based on original questioner's comments, to remove the question from the unanswered queue. –  Graham Miln Jan 25 '13 at 12:41
2  
Well, if you want to keep other content of your profile, a simple /bin/mv ~/.bash_profile ~/bash_profile might be better –  patrix Jan 25 '13 at 17:40

These methods are great! If you have this problem with zsh, remove ~/.zshrc This will get rid of your zsh settings though.

share|improve this answer

OSX's default $PATH is generated from the contents of the /etc/paths file, it's fairly straight-forward to modify.

share|improve this answer
    
Modifying /etc/paths carries the risk of changes getting overwritten by the next OS X update, also this doesn't work for user-specific paths like ~/bin. –  patrix Jun 18 at 7:00
    
That's true, though I usually handle those in my .rc's later. I also haven't had my /etc/paths reset yet by an update (several years now since I started using brew). –  Chris Keele Jun 18 at 7:06
    
Currently hacking on a boxen provisioning that I hope will make me impervious to future overwriting updates. –  Chris Keele Jun 18 at 7:10

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.