bash: sudo: command not found on OS X Lion

17,102

Solution 1

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.

Solution 2

Did sudo ever disappear entirely? Did you replace it by the file you got from the other machine? I wonder how you even managed to delete sudo. RVM runs without elevated privileges, and it should never have had the permissions to do things like this.


Anyway, try and restore from your latest backup. If you don't have one, then repair permissions through Disk Utility. Might help.

You could attempt to boot the Mac into single user mode. Do this by holding Command-S while booting. Here, enter

mount -uw /

And then try to chmod the file properly. Something along:

chown root /usr/bin/sudo 
chmod u+s /usr/bin/sudo

If that all fails, just reinstall Lion – that's what recovery is for. It won't delete your files. You'd have to wipe the disk clean in order to lose anything, but I would strongly advise to make a backup.

Share:
17,102

Related videos on Youtube

Matt H.
Author by

Matt H.

Updated on September 18, 2022

Comments

  • Matt H.
    Matt H. over 1 year

    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.