Every time I try to use a sudo or ssh command, it returns with this error:

when:~ jackson1442$ sudo [insert any command here]
-bash: sudo: command not found

I was messing with Python installs, and am not sure what I did to cause this. How can I permanently fix this?

macOS Sierra 10.12.4 16E195
MacBook Pro 2016
13" Touchbar

EDIT: here's the path:

when:~ jackson1442$ echo $PATH

Here is .bash_profile

# Setting PATH for Python 2.7
# The original version is saved in .bash_profile.pysave
export PATH

# Setting PATH for Python 3.6
# The original version is saved in .bash_profile.pysave
export PATH

# Setting PATH for Python 3.5
# The original version is saved in .bash_profile.pysave
export PATH
export PATH=’/usr/local/bin:��
  • @klanomath sorry about the delay Here it is: when:~ jackson1442$ echo $PATH ’/usr/local/bin:?? – Jackson1442 May 2 '17 at 2:52
  • After commenting out or removing the last line and sourcing your profile the PATH should be at least .../3.5/bin:.../3.6/bin:/.../2.7bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin now (I omitted each /Library/Frameworks/Python.framework/Versions/ here). – klanomath May 2 '17 at 3:50
  • @klanomath affirmative. It works! Not sure how that one at the end got there... – Jackson1442 May 2 '17 at 4:12
  • This is the culprit: export PATH=’/usr/local/bin:�� – Thorbjørn Ravn Andersen Dec 13 '20 at 9:28

Your PATH is hosed!

First check your .bash_profile file with:

/usr/bin/nano ~/.bash_profile

Prepend lines containing something like export PATH="/... " with a # to comment them out. Save the file with ctrlO and exit nano with ctrlX

Then check /etc/paths with: /bin/cat /etc/paths.

It should look like this:


You can edit the file with /usr/bin/sudo /usr/bin/nano /etc/paths if required.

If everything is fine enter source ~/.bash_profile or close the Terminal window and open a new one.

Now sudo should work again. Then check all #export PATH=... lines in your .bash_profile for potential errors. You may add them to your question to get help here.

  • There is nothing in .bash.profile – Jackson1442 May 2 '17 at 3:35
  • Thanks, my bad. I just had to quit terminal after commenting out that last funky line. – Jackson1442 May 2 '17 at 3:42
  • Thanks between using brew and conda the bash_profile had python PATH's all over the place. My work wasn't affected until we started to use ansible that insisted on using sudo. Though this did the trick. – tourdownunder Sep 1 '17 at 22:34

Magic Answer

export PATH="/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin"
  • 1
    This'll restore basic function to the current shell, but leaves out any additions to the standard PATH (e.g. the asker's additional versions of python), and it's not a permanent fix (that requires debugging the shell init files to find what's causing the problem). – Gordon Davisson Dec 13 '20 at 6:31

sudo launchctl load -w /System/Library/LaunchDaemons/com.apple.locate.plist

  • 3
    If the OP states: sudo [insert any command here] -bash: sudo: command not found why should another command starting with sudo ... suddenly help/work? – klanomath May 2 '17 at 4:17

You must log in to answer this question.

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