Permission problems

I am trying to run brew doctor and I am getting the folowing error

$ brew doctor
==> Downloading https://homebrew.bintray.com/bottles-portable/portable-ruby-2.3.3.leopard_64.bottle.1.tar.gz
Already downloaded: /Users/leptos/Library/Caches/Homebrew/portable-ruby-2.3.3.leopard_64.bottle.1.tar.gz
mkdir: /usr/local/Library/Homebrew/vendor/portable-ruby: Permission denied
/usr/local/Library/Homebrew/brew.sh: line 55: cd: /usr/local/Library/Homebrew/vendor/portable-ruby: No such file or directory
Error: Error: failed to cd to /usr/local/Library/Homebrew/vendor/portable-ruby!
Error: Failed to install vendor Ruby.

Then I try to use:

$ sudo brew doctor
Error: Running Homebrew as root is extremely dangerous and no longer supported.
As Homebrew does not drop privileges on installation you would be giving all
build scripts full access to your system.

I am lost. I have no clue what to do other than reinstalling it.

what happens when you run ls -al /usr/local?

do you mean this?

drwxr-xr-x 23 root wheel 782 Oct 30 2017 Cellar

Yeah, your Cellar being owned by root could very well be what’s the issue here. If you run sudo chown -R $(whoami):wheel /usr/local brew should be able to install things again.

Yes it works! Thanks!
But I did sudo chown -R $(whoami):wheel /usr/local/Cellar should I still do sudo chown -R $(whoami):wheel /usr/local? Also what is the difference between the Homebrew folder and the Cellar? There is also a Frameworks folder and a Caskroom folder that are empty. What are these for? Thank you once again!

Doing chown on /usr/local might be better. Homebrew contains the brew command, the cellar contains the installed software, Frameworks is required for things that work with python (I don’t know specifics but it’s needed, trust me :grin:) and the caskroom is for casks (which can be applications with a GUI or anything that doesn’t strictly fit the homebrew rules for formulae)

Got it. Thank you very much for your help!

This does not work on macOS Mojave or Catalina. I just get the following error:
chown: /usr/local: Operation not permitted

Apple also recommends that we use zsh as our new default shell :laughing:

It works fine for me on mojave and Catalina is a developer beta so I have no idea what that’s doing, nor does homebrew support known broken versions of macOS.

How do you go about installing?

I ma having the same issue in my Mojave!
chown: /usr/local: Operation not permitted

What happens when you use /usr/local/*?

It got fixed now. I think updating brew solved it for me.
Thank you

@Rahmo which brew version do you have? It still fails for me on Majave 10.14.6 with Homebrew 2.1.11

Both commands fail:
(1) sudo chown -R $(whoami):wheel /usr/local/ => chown: /usr/local/: Operation not permitted
(2) sudo brew install swiftlint => Error: Running Homebrew as root is extremely dangerous and no longer supported.

sudo chown -R $(whoami):wheel /usr/local/* should do the trick.

conforming: yes, it did the trick. thanks @SMillerDev

I’m facing this same problem. I have tried latest command here:

sudo chown -R $(whoami):wheel /usr/local/

But after that running: sudo brew doctor I get response:

Error: Running Homebrew as root is extremely dangerous and no longer supported.
As Homebrew does not drop privileges on installation you would be giving all
build scripts full access to your system.

My MAC version is 10.14.6

What can I try next?

Hi, I am using Mojave and I have used sudo chown -R $(whoami):wheel /usr/local/* and it is still not working. It still says:
Could not create /usr/local/Cellar
Check you have permission to write to /usr/local
obviously that’s because I still don’t have access to local I am admin. I am at a loss

You just shouldn’t run sudo brew. Running Homebrew as root is extremely dangerous. As Homebrew does not drop privileges on installation you would be giving all build scripts full access to your system.

what does ls -al /usr/local/ say?