Want to highlight a helpful answer? Upvote!

Did someone help you, or did an answer or User Tip resolve your issue? Upvote by selecting the upvote arrow. Your feedback helps others! Learn more about when to upvote >

Looks like no one’s replied in a while. To start the conversation again, simply ask a new question.

sudo: command not found

Hello


On this iMac (late 09, new ssd), terminal does not accept the command 'sudo', it says

"sudo: command not found"

other commands, like "ls" are working.


The system is the same as before the hd went down (the old hard disc has beed mirrored)...


what could be the reason of such troubles?


Thank you!


david

iMac, macOS High Sierra (10.13.3)

Posted on Nov 30, 2018 2:14 AM

Reply
Question marked as Best reply

Posted on Nov 30, 2018 8:23 AM

Sounds like your PATH environment variable may be messed up.


/usr/bin/sudo # is where the sudo command is stored


These are the directories that should be in a default user account's PATH:

/usr/bin

/bin

/usr/sbin

/sbin

You can use either of these commands to see your PATH

echo $PATH

or an easier to read output using:

echo $PATH|awk '{gsub(/:/,"\n") ;print}'


So do you have one of the following files?

/bin/ls $HOME/.bash_profile

/bin/ls $HOME/.bash_login

/bin/ls $HOME/.bashrc

/bin/ls $HOME/.profile

By default, none of these files exist, but when someone reports they cannot execute some command that should be on every Mac, it is very common that they have one of the above files and it has a mistake that does not modify the PATH environment variable correctly.

Similar questions

5 replies
Question marked as Best reply

Nov 30, 2018 8:23 AM in response to david braun

Sounds like your PATH environment variable may be messed up.


/usr/bin/sudo # is where the sudo command is stored


These are the directories that should be in a default user account's PATH:

/usr/bin

/bin

/usr/sbin

/sbin

You can use either of these commands to see your PATH

echo $PATH

or an easier to read output using:

echo $PATH|awk '{gsub(/:/,"\n") ;print}'


So do you have one of the following files?

/bin/ls $HOME/.bash_profile

/bin/ls $HOME/.bash_login

/bin/ls $HOME/.bashrc

/bin/ls $HOME/.profile

By default, none of these files exist, but when someone reports they cannot execute some command that should be on every Mac, it is very common that they have one of the above files and it has a mistake that does not modify the PATH environment variable correctly.

Nov 30, 2018 7:40 AM in response to david braun

From terminal type:

echo $PATH


You should see a list of all the directories (separated by colons) where the shell looks for commands to execute when you type something. For my system the list is:

/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/opt/X11/bin


The sudo command is in /usr/bin

To see that the file is there and what its ownership and permissions are type:

ls -l /usr/bin/sudo


For my system:

-r-s--x--x
1 root
wheel
370704 Oct 26 15:00 /usr/bin/sudo

The sudo command with those permissions works for me. If yours are different, you may have found the "root" cause. 🙂

If Disk Utility offers "Repair Permissions" on your system, that may fix the problem. If not, you'll probably have to use chmod from the terminal.

Best,

Dan

Nov 30, 2018 8:39 AM in response to BobHarris

Good evening Bob


Thanks very much. Even though this is way above my understanding/knowledge, it is good to have something to byte...

echo $PATH|awk '{gsub(/:/,"\n") ;print}' results in -bash: awk: command not found


so I don't know if the files you mention are present or not.

echo $PATH returns /usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin


Anyway, I am not the man to delve into terminal-stuff (not beyond some copy-paste-stuff anyway), but on the other hand I feel uncomfortable knowing that something's wrong there. I'd like to fix it—the mac-way. Would it make sense to just reinstall the system? Or is there a possibility that stuff buried deep inside have gotten bad?


Thanks again

dave

Nov 30, 2018 10:36 AM in response to david braun

The error message for the command from Bob means the system is not finding the awk command either.


Looks like your $PATH variable is not the problem. Could be you don't have permissions for your account to use one or more of the key directories or commands. Try to list the files in each of the directories in your path with:


ls -a [name of the directory here]


Make sure they all have commands in them. See if you can spot "awk" or "sudo" anywhere. If any of the command directories shows as "not found" by the ls command, that's your problem. It could be "not found" because it's not there or because you don't have permission to browse it.


Use "ls -alF" in your home directory to see if any of the files Bob mentioned are present. Chances are they would have wrecked things by messing up the $PATH variable.


You might also try:

1) Use DiskUtility "First Aid" on the SSD

2) In the Terminal application, close completely out of the current shell with "control-D" (may require multiple contol-D commands, if multiple shells have been spawned. Then open a new terminal window to create a fresh shell environment and see if "sudo ls -a" will work.

sudo: command not found

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple ID.