So I’m a bit of a terminal noob so bear with me but I was trying to update brew to install something, so I ran: brew update
and got Error: /usr/local must be writable!
Wasn’t really sure what that was about so I tried running sudo brew update
and got sudo: effective uid is not 0, is sudo installed setuid root?
Not sure if this helps but running ls -l $(which sudo)
gave me:
ls: is: No such file or directory ls: is: No such file or directory ls: is: No such file or directory ls: is: No such file or directory ls: sudo: No such file or directory ls: sudo: No such file or directory ls: sudo: No such file or directory ls: sudo: No such file or directory -r-s--x--x 1 root wheel 369136 Sep 13 20:56 /usr/bin/sudo -r-s--x--x 1 my_profile admin 168448 Jan 13 2016 /usr/local/bin/sudo -r-s--x--x 1 my_profile admin 168448 Jan 13 2016 /usr/local/bin/sudo -r-s--x--x 1 my_profile admin 168448 Jan 13 2016 /usr/local/bin/sudo
I tried the suggestion here (using Disk Utility and running First Aid) but it didn’t seem to have any effect….
Can anyone tell me what’s going on and what I need to do?
Advertisement
Answer
If you run ls -la /usr
, the result most likely will be something like below:
total 0
drwxr-xr-x@ 11 root wheel 374 Oct 14 14:35 .
drwxr-xr-x 32 root wheel 1156 Oct 26 09:49 ..
drwxr-xr-x 19 root wheel 646 Oct 10 18:51 local
... (some other files and directories)
Now it’s obvious from the above that unless you are logged in as a root
or your user is in the wheel
group (which is most likely not), any command you issue with your user which needs write permission (such as brew update
) will fail.
One of the possible solutions (and I am not claiming is the best one) would be to change permissions of /usr/local
.
Like so:
sudo chown -R $(whoami) /usr/local
Interestingly enough, if you then run
brew update
all goes well and you get the following message:
=> Migrating HOMEBREW_REPOSITORY (please wait)...
==> Migrated HOMEBREW_REPOSITORY to /usr/local/Homebrew!
Homebrew no longer needs to have ownership of /usr/local. If you wish you can
return /usr/local to its default ownership with:
sudo chown root:wheel /usr/local
Which I guess explains what happened in the first place.
Hope that helps.