Macos – bash: sudo: command not found on OS X Lion

command linemacossudo

This baffles me.

sudo [any command here ]
bash: sudo: command not found

Eek!

I tried to uninstall the Ruby Version Manager (it wouldn't compile Ruby for some reason).
Somewhere in following their step-by-step instructions, I became sudo-less.

Here is my $PATH: /usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/X11/bin

which sudo returns nothing.

I figured I'd try a shot-in-the-dark while I was waiting. I have an older Mac that I just upgraded to Lion two days ago. I copied its /usr/bin/sudo onto the problem machine. Now when I attempt to sudo, I get:

sudo: must be setuid root

I'm not particularly savvy with the command line — this seems bad.

Best Answer

Try using Disk Utility to repair file permissions -- with any luck, that should reset the setuid bit on the /usr/bin/sudo that you copied. It's a flag that lets sudo act as root even when it's not run as root, which obviously it needs to be able to do, but you'll need sudo to set it using the command line so you have a chicken-and-egg problem.

Related Question