Messed up $PATH variable in Mac OS X

I did something to my PATH.

I was trying to add some new path and now none of the command like open ~/.bash_profile work, and echo $PATH only shows one path which is /Application/Filename.

Is there a way to fix this? This is my Mac OS X Lion.


Solution 1:

If you messed up your ~/.bash_profile you can always edit it by supplying the absolute path to the editor:

/usr/bin/nano ~/.bash_profile

Remove any changes to PATH and press CtrlO, then . Overwrite the file and reload your shell. Your path settings should be restored.

Other files that set your PATH on OS X are:

  • ~/.bash_login (if ~/.bash_profile doesn't exist)
  • ~/.profile (if ~/.bash_login doesn't exist)
  • /etc/profile
  • Everything in /etc/paths.d/
  • Finally, for GUI apps: ~/.MacOSX/environment.plist

Always remember to use the correct formatting for your new PATH, depending on whether you want your custom binaries to take precedence over system binaries:

export PATH=/some/other/path:$PATH

… or the other way 'round:

export PATH=$PATH:/some/other/path