Homebrew install permissions issue

2020-02-07 17:28发布

问题:

I have a standard homebrew install inside of usr/local/

When I try:

Larson-2:~ larson$ brew install postgresql
Error: Cannot write to /usr/local/Cellar

And when I use sudo:

Larson-2:~ larson$ sudo brew install postgresql
Cowardly refusing to `sudo brew install'

What am I doing wrong?

回答1:

You somehow have limited permissions to /usr/local/Cellar. Brew doesn't like to install with sudo which is why it refuses.

Check the permissions:

ls -ld /usr/local/Cellar

Open them up for writing:

sudo chmod a+w /usr/local/Cellar



回答2:

Do not use sudo when working with brew (for security reasons).

You've to simple set-up your permissions.

So I would go even further and change the permissions to:

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

and then apply the specific group (either admin or staff) to user which should be allowed to use brew command. Check groups of your user via: id -Gn).

If there are further issues, run: brew doctor to see what's wrong.



回答3:

I'd change the group permissions:

$ chgrp -R admin /usr/local/Cellar
$ chmod g+w /usr/local/Cellar

assuming your user account is in group admin.



回答4:

This also happens if you have multiple users on your machine. If so, it would be best for you to change the user since every other approach would have you messing around with a lot more files and folders than just /usr/local/Cellar

Use su userWhoInstalledBrew.



回答5:

The problem can be solved by changing the directory's owner to the current user:

sudo chown -R $USER /usr/local

This answer is taken from: https://github.com/Homebrew/homebrew/issues/17884