2

Recently, I've been unable to use the sudo command in terminal. Any command I try to give it, file I try to get it to run, etc, tells me sudo: [command or file]: command not found. If I try to run sudo without any arguments though, it tells me the usage and what arguments I am allowed to use with sudo, so I know the system is at least aware of sudo — it's just broken.

I've followed the answers to all the other questions i've seen with a similar issue, but none of them have helped.

echo $PATH gives me /usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin, so that's all set properly

I don't believe .bash_profile is in use (I'm on Apple silicon which means it uses .zprofile instead, from what I understand?), but I set the PATH there just in case. .zprofile had some changes to it from installing python, but I commented those out and set the PATH anyway just to be safe. Still nothing.

# The original version is saved in .zprofile.pysave
#PATH="/Library/Frameworks/Python.framework/Versions/3.11/bin:${PATH}"
#export PATH
PATH="/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin"
export PATH

What's going on?

7
  • Is the command actually in any of those paths? What happens if you use the full path?
    – red_menace
    Commented Sep 28, 2023 at 23:39
  • Yes, sudo is present in usr/bin. Using the full path still gives the same command not found error
    – GtwoK
    Commented Sep 28, 2023 at 23:54
  • Seems like the full path is not correct - are spaces or other characters special to the shell properly escaped?
    – red_menace
    Commented Sep 29, 2023 at 0:05
  • 1
    I would say test with something simple like sudo ls before making the claim that sudo might be broken. Commented Sep 29, 2023 at 1:01
  • 4
    The error isn't saying that sudo isn't found. It says that the command you're trying to run with it isn't found.
    – Barmar
    Commented Sep 29, 2023 at 1:11

1 Answer 1

1
$ sudo foo
sudo: foo: command not found

indicates that sudo couldn‘t access the command you want to run. Typical reasons for this are

  • the command (binary) does not exist,
  • the command is not in $PATH,
  • root (or whatever user you sudo to) doesn't have access to the command file (needs to have o+x rights on all directories in the path, and o+rx on the command file itself).
4
  • Ah! Seems to be a permissions thing. chmod 755 [file] fixed it. But the file was just in my documents... why would permissions be restrictive there? Is there a way to get around this so I dont have to chmod every file and folder needed by the .command file?
    – GtwoK
    Commented Sep 29, 2023 at 18:38
  • 1
    @GtwoK why do you need sudo at all in that case?
    – nohillside
    Commented Sep 29, 2023 at 18:47
  • And if you did run it with sudo and it ended up creating new files in your home directory, those too will now be owned by root and you will be unable to do anything with them. Stop using sudo needlessly.
    – tripleee
    Commented Dec 14, 2023 at 17:57
  • If the file was not executable at all, that would explain why it could not be found. Even sudo will not be able to execute things which are not executable (at least not easily).
    – tripleee
    Commented Dec 14, 2023 at 17:58

You must log in to answer this question.

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