Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

This baffles me.

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


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.

share|improve this question
up vote 3 down vote accepted

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.

share|improve this answer
this worked perfectly. thanks! – Matt H. Dec 17 '11 at 20:09

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|improve this answer

I see Mike Scott's post answered your sudo issue, but I also hit the issue with RVM not compiling Rubies. It seems Apple shifted to using LLVM as the default compiler in 10.7 and so linked gcc to llvm-gcc.

$ which gcc                                                                  

$ ls -la /usr/bin/gcc                                                        
lrwxr-xr-x  1 root  wheel  12 30 Nov 13:40 /usr/bin/gcc -> llvm-gcc-4.2

gcc is still there, but it's at /usr/bin/gcc-4.2. Specifying the C Compiler to use by setting the CC environment variable should allow you to compile rubies.

$ CC=/usr/bin/gcc-4.2 rvm install 1.9.2
share|improve this answer

You must log in to answer this question.

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