54

I've been trying to get homebrew working nicely, but it appears everything inside /usr/local isn't writable, and everything falls over.

It keeps telling me to recursively chown /usr/local, and I tried that. Operation denied, so I sudo'd it. It seemed to work, but with an eerie silence that I hear is considered polite in Unix. Unfortunately, any succeeding attempts at brew update meet with the same cacophony of errors.

I reran the command with -v and it looks the operation is not permitted for anything inside.

As much as the answer is probably "learn UNIX" I'm just trying to comply with some job requirements here for a tutorial on Ruby, so that's a few steps above where I'm currently at.

brew doctor:

Warning: /usr/local/Frameworks isn't writable.

This can happen if you "sudo make install" software that isn't managed by
by Homebrew. If a formula tries to write a file to this directory, the
install will fail during the link step.

You should probably `chown` /usr/local/Frameworks
Warning: /usr/local/Cellar isn't writable.
You should `chown` /usr/local/Cellar
Warning: /usr/local/etc isn't writable.

This can happen if you "sudo make install" software that isn't managed by
by Homebrew. If a formula tries to write a file to this directory, the
install will fail during the link step.

You should probably `chown` /usr/local/etc
Warning: /usr/local/include isn't writable.

This can happen if you "sudo make install" software that isn't managed by
by Homebrew. If a formula tries to write a file to this directory, the
install will fail during the link step.

You should probably `chown` /usr/local/include
Warning: /usr/local/lib isn't writable.

This can happen if you "sudo make install" software that isn't managed by
by Homebrew. If a formula tries to write a file to this directory, the
install will fail during the link step.

You should probably `chown` /usr/local/lib
Warning: /usr/local/lib/pkgconfig isn't writable.

This can happen if you "sudo make install" software that isn't managed by
by Homebrew. If a formula tries to write a file to this directory, the
install will fail during the link step.

You should probably `chown` /usr/local/lib/pkgconfig
Warning: /usr/local/opt isn't writable.
You should `chown` /usr/local/opt
Warning: /usr/local/share isn't writable.

This can happen if you "sudo make install" software that isn't managed by
by Homebrew. If a formula tries to write a file to this directory, the
install will fail during the link step.

You should probably `chown` /usr/local/share
Warning: Some directories in /usr/local/share/man aren't writable.
This can happen if you "sudo make install" software that isn't managed
by Homebrew. If a brew tries to add locale information to one of these
directories, then the install will fail during the link step.
You should probably `chown` them:

    /usr/local/share/man
    /usr/local/share/man/man1
    /usr/local/share/man/man3
    /usr/local/share/man/man5
    /usr/local/share/man/man7
    /usr/local/share/man/man8
Warning: /usr/local/var isn't writable.

This can happen if you "sudo make install" software that isn't managed by
by Homebrew. If a formula tries to write a file to this directory, the
install will fail during the link step.

You should probably `chown` /usr/local/var
5
  • Does brew doctor tell you anything useful? Post the output here.
    – Ian C.
    Commented Jun 19, 2015 at 5:47
  • @IanC. It's a long list of everything brew-related not being writable. Is there a stackexchange pastebin utility? There's an awful lot of it.
    – Tigt
    Commented Jun 19, 2015 at 5:50
  • Well, that's odd. There's a lot less of it now than there was.
    – Tigt
    Commented Jun 19, 2015 at 5:52
  • Just FYI: I just ran brew update and discovered that "Homebrew no longer needs to have ownership of /usr/local." More info in this question. Obviously to get to that point you'd still need to temporarily update permissions on /usr/local :)
    – acobster
    Commented Nov 19, 2016 at 21:16
  • Can someone explain to me why mac got rid of our permissions? Commented Jun 2, 2020 at 21:53

6 Answers 6

49

This should be solved changing the perms on that directory in the following way:

$ cd /usr/local
$ sudo chown -R <your-username>:<your-group-name> *

If you don't know your group, just type id -g.

11
  • 13
    Why is it right for /usr/local to be owned by your user? I think that is a security risk, as there are a lot of other programs that use /usr/local and could be silently taken over. Does brew really need something so drastic?
    – dfrankow
    Commented Jul 11, 2016 at 17:48
  • 2
    I believe this is dangerous as it selects the 'staff' group, which means every user on the OS can then alter the contents of /usr/. You should probably switch to 'admin'.
    – Indolering
    Commented Apr 14, 2017 at 23:48
  • 5
    @dfrankow yep, this is a blunder of homebrew. They didn't think even what happens if there're two users on same machine.
    – poige
    Commented Jan 6, 2019 at 18:08
  • 1
    Pretty sure this creates a security vulnerability. However it is the official suggested solution from brew. Commented Jun 5, 2020 at 17:28
  • 2
    @dfrankow (and others) Yes it's a security vulnerability and it's pathetic of homebrew. It's reason enough to not use it. I use MacPorts instead. Unfortunate as I do want to test something with homebrew but there's not a chance of that whilst it requires taking over /usr/local.
    – Pryftan
    Commented Dec 7, 2021 at 16:14
28

You have to use sudo to run the command with elevated priledges, like this:

sudo chown -R `whoami` /usr/local/*
5
  • I did. "Operation denied, so I sudo'd it."
    – Tigt
    Commented Jun 19, 2015 at 5:44
  • 1
    For fish shell users it will be sudo chown -R (whoami) /usr/local Commented Nov 30, 2016 at 21:15
  • 2
    This must be done of the files/folders inside of /usr/local but not on this directory per se, e.g. sudo chown -R `whoami` /usr/local/* Commented Jan 23, 2021 at 20:03
  • haha.. very elegant. Commented May 10, 2022 at 0:27
  • @HenriqueGontijo good point. Fixed.
    – Ian C.
    Commented May 29, 2022 at 14:06
17

I was facing this issue yesterday with macOS 10.13.4 and I tried to sudo chgrp -R admin /usr/local or sudo chown -R <your-username>:<your-group-name> /usr/local which get Operation not permitted error even though using sudo

So I tried to just chgrp for Homebrew related folder to admin (My user is in admin group, depends on the user you are running, you might need to change to a different group) and grant admin group write access to those folders using these commands

sudo chgrp -R admin /usr/local/Homebrew/
sudo chmod -R g+w /usr/local/Homebrew/
sudo chgrp -R admin /usr/local/var/homebrew/
sudo chmod -R g+w /usr/local/var/homebrew/

After running these commands, I am able to install a new package without any issue. If you hit any permission issue again try to run the first two commands by replacing the folder name with the one that you are hitting permission issue.

Hope this will help the other users with macOS 10.13.

Note: Even though changing the owner for /usr/local or changing the group of /usr/local and grant the access for you group might work, you should NEVER do that as you are modifying the other unrelated folder as well. Modifying the folder(s) you need is much more secure.

0
14

The answer by Reza in this question worked for me:

sudo chown -R $(whoami) /usr/local/*

You can not change permission for /usr/local itself , but you can change the right permission for folders underneath

0
2

to resolve the permissions issues on the directories we can perform the following command:

brew prune
1
  • brew prune has been replaced by and is now run as part of brew cleanup
    – lodeOfCode
    Commented Nov 3, 2020 at 19:39
0

It worked for me.

sudo chgrp -R admin /usr/local
sudo chmod -R g+w /usr/local

You must log in to answer this question.

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