139

Homebrew needs permissions in /usr/local and since no one else uses my laptop I have always simply done

sudo chown -R $(whoami) $(brew --prefix)

but in High Sierra, this gives

chown: /usr/local: Operation not permitted

What is the fix?

pkamb
  • 33,281
  • 23
  • 160
  • 191
Dan
  • 2,851
  • 3
  • 20
  • 27
  • 3
    Solved with : sudo chown -R "$USER":admin /usr/local/* – Marcelo Campusano Sep 09 '19 at 22:17
  • 2
    Adding `/*` to the end like so: `sudo chown -R $(whoami) $(brew --prefix)/*` worked for me – Brian Rodriguez Feb 02 '21 at 02:17
  • What happened on my machine is I got the "permission denied" error, but when I ls -l it still lists all directories as the new chowner I just assigned, but did not change the actual permissions, so some Homebrew directories still get "permission denied" errors when updating yet the owner is the new owner. – Marsellus Mar 13 '22 at 01:20

11 Answers11

254

The problem kept occurring... after digging deeper I found that only uninstalling Homebrew and then re-installing it solved this issue.

Uninstalling will remove all your brew packages, you can save the output of brew list in a file first, to have a record of what packages were installed.

Uninstall Homebrew:

/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/uninstall)"

Then re-install it:

/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
Uri Meirav
  • 3,120
  • 1
  • 17
  • 10
  • 5
    this was the only way to fix my homebrew after "High" Sierra upgrade. my error was: `gh4x-mbpr:~ gh4x$ brew link git Linking /usr/local/Cellar/git/2.15.0... Error: Permission denied @ dir_s_mkdir - /usr/local/lib` and `sudo chown -R $(whoami) $(brew --prefix)/*` didnt help... – gh4x Dec 06 '17 at 21:28
  • 1
    Unbelievable. Failed the first time, uninstall script failed, second install worked. – GreenAsJade May 01 '18 at 06:30
  • 3
    You might like to save the output of `brew list` in a file first, to have a record of what packages were installed. – Giles Gardam Aug 29 '18 at 18:57
  • 1
    None of the other various Mojave homebrew fixes would work on my system. Uninstall/Reinstall worked perfectly. – pkamb Jan 20 '19 at 23:31
  • Been searching for a solution to chown: /usr/local: Operation not permitted for an hour or so. This was the only solution that worked out of many others. – Leafyshark Aug 31 '19 at 20:41
  • I think @Reza Farshi is the best. This answer doesn't actually explain what was creating the issue, or how it is fixed. – Jordan Stewart Oct 30 '19 at 03:57
  • 2
    Works also with Catalina – Gefilte Fish Nov 05 '19 at 14:59
  • 1
    FYI. Uninstalling removes all of your brew packages – John Dec 01 '20 at 00:52
  • This still works on Big Sur. I was getting bunch of 'permission denied' errors when trying to install a package (azure-cli). brew update, upgrade, doctor, did not help. Uninstalling and reinstalling worked. Thanks. – yaach Oct 03 '21 at 21:58
65

Unfortunately you can no longer chown /usr/local in High Sierra. A workaround is to sudo mkdir /usr/local/include and /usr/local/Frameworks if they don't exist, and

sudo chown -R $(whoami) $(brew --prefix)/*

Thanks to ilovezfs for this simple workaround and for the amazing homebrew!

Dan
  • 2,851
  • 3
  • 20
  • 27
53

You can not change permission for /usr/local itself , but you can change the right permission for folders underneath , so this fixed the
sudo chown -R $(whoami) /usr/local/*

Reza Farshi
  • 963
  • 7
  • 9
11

I am using MacBook Pro macOS Catalina 10.15.4.

I created a new admin account but the brew was throwing an error.

Hence, I followed a step from this post, what worked is:

sudo chown -R $(whoami) $(brew --prefix)/*

Not A Bot
  • 2,474
  • 2
  • 16
  • 33
koushik v
  • 223
  • 6
  • 16
8

I followed this but the problem still persist.
So, I reinstalled homebrew without uninstalling previous one. It's working now!
(I don't know how)

Aayush Gautam
  • 181
  • 1
  • 6
  • 3
    I recommend to completely uninstall Homebrew & then install it again. – k1r8r0wn Oct 07 '17 at 04:16
  • Multiple installed did work, I wasn't able to fix it until I uninstalled. – cbowns Jan 08 '18 at 00:54
  • uninstalling will screw everything up. I have tons of packages installed and will have to go through and install them all over again. Sadly this all worked previously because I HAVE those packages. – jaydel Sep 08 '19 at 17:36
6

I just run this and everything gets taken care on high sierra:

/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

4

Try disabling System Integrity Protection. From the documentation:

System Integrity Protection can be configured using the csrutil(1) command.

You can check whether System Integrity Protection is currently enabled on your system by running the following command in the Terminal:

$ csrutil status
System Integrity Protection status: enabled.

To enable or disable System Integrity Protection, you must boot to Recovery OS and run the csrutil(1) command from the Terminal.

Boot to Recovery OS by restarting your machine and holding down the Command and R keys at startup. Launch Terminal from the Utilities menu. Enter the following command: $ csrutil enable

After enabling or disabling System Integrity Protection on a machine, a reboot is required.

Elle Mundy
  • 2,099
  • 1
  • 19
  • 12
  • Whilst this may theoretically answer the question, [it would be preferable](//meta.stackoverflow.com/q/8259) to include the essential parts of the answer here, and provide the link for reference. – Jake Symons Feb 20 '18 at 19:05
  • 3
    This is a little like removing the guard from your table saw. It works, and it might be necessary sometimes, but it's safer if you don't have to do it. Setting yourself as the owner of /usr/local to make homebrew work always seemed like a hack anyway. – Caleb May 17 '18 at 06:12
  • 3
    This is highly discouraged! It's extremely dangerous unless the user doesn't what he/she is doing. – Abu Shumon Nov 08 '18 at 13:48
  • @oligofren :D :D :D come on man. Relax, it's not an english `word in context` contest. :D :D Flag to warn user. But alright, you pick up wordings for me then :p :p – Abu Shumon Mar 06 '19 at 14:21
2

if you are using zsh because you come from bash you might have to change your $PATH. you should add export PATH=$HOME/bin:/usr/local/bin:$PATH in .zshrc

then it should work, this problem resolved in my mac by this way.

zyqbit
  • 21
  • 1
1

I'm also on 10.13 High Sierra. I tried the previous suggestions; nothing worked. Eventually I tried installing the command-line tools first:

xcode-select --install

and then afterwards (re-)ran the brew install command:

/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

and it finally worked.

Ed Mechem
  • 31
  • 2
0

Make sure you don't have a lock set on the home folder or any folder an install needs access to.

Even if the permissions and ownership are set correctly and you are currently logged in with a correct user/or Root user it will not allow you to make new folders or directories.

ChrisF
  • 134,786
  • 31
  • 255
  • 325
Daniel
  • 1
0

I did not have the /user/local/Frameworks folder, so this fixed it for me

sudo mkdir -p /usr/local/Frameworks
sudo chown -R $(whoami) /usr/local/Frameworks

I have OSX High Sierra

Pathak Ayush
  • 726
  • 12
  • 24