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:


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.

  • 5
    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 – David Smith Jan 21 '13 at 12:37

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:


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.

| improve this answer | |

I recommend:

source /etc/profile

This is what Mac uses to set the initial path, and it will put everything back in place excepting the items that you are adding for your user.

I do a decent amount of path modification in my ~/.bash_profile, and I've placed this at the top of the file because I was having issues with reloading my profile while I'm working after I tweak an alias in there or something, and it was adding duplicate references to my path. Instead of checking to see if it's already added, I just reset my path to the scratch version and re-append the items I want.

UPDATE: When switching to zsh, I changed my .bash_profile to .zshrc and then changed my reload profile alias to source the /etc/zprofile, which resets the path to scratch as described earlier for bash. Here's the alias I have defined so that I can quickly reload my profile:

alias reloadprofile='source /etc/zprofile && source ~/.zshrc'

I believe you can accomplish the same thing by calling exec zsh, which replaces the current instance with a new one and reloads the .zshrc file, but I haven't experimented enough with it to be completely sure.

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

| 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
  • 5
    Well, if you want to keep other content of your profile, a simple /bin/mv ~/.bash_profile ~/bash_profile might be better – nohillside Jan 25 '13 at 17:40
  • 1
    This is the simplest answer I have found in the entire SE websites. Thanks! – mr5 Jun 26 '18 at 2:41
  • 1
    Most effective answer for sure – famouspotatoes Mar 25 at 2:39

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

| improve this answer | |
  • 1
    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. – nohillside Jun 18 '14 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 '14 at 7:06
  • Currently hacking on a boxen provisioning that I hope will make me impervious to future overwriting updates. – Chris Keele Jun 18 '14 at 7:10

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

| improve this answer | |
  • You would rather want to keep a copy /bin/mv ~/.bash_profile{,.bck} – MauroPorras Dec 21 '16 at 15:53

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .