Permission problems

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

$ brew doctor
==> Downloading
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/ 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