How to reset $PATH?
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.
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.
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.
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.