我已经卸载和安装了3次Homebrew,因为它似乎永远不允许我安装任何东西,因为它在大多数安装结束时拒绝我的权限。

作为一个例子,我将发布我目前面临的libjpeg下载场景。

我尝试安装libjpeg并获得:

$ brew install libjpeg
==> Downloading https://downloads.sf.net/project/machomebrew/Bottles/jpeg-8d.mountain_lion.bottle.1.tar.gz
Already downloaded: /Library/Caches/Homebrew/jpeg-8d.mountain_lion.bottle.1.tar.gz
==> Pouring jpeg-8d.mountain_lion.bottle.1.tar.gz
Warning: Could not link jpeg. Unlinking...
Error: The brew link step did not complete successfully
The formula built, but is not symlinked into /usr/local
You can try again using `brew link jpeg'
Error: Permission denied - /usr/local/opt/jpeg

'brew link jpeg'的结果

Error: Permission denied - /usr/local/opt/jpeg

这是我的酿酒医生读的

$ brew doctor
Warning: "config" scripts exist outside your system or Homebrew directories.
./configure scripts often look for *-config scripts to determine if
software packages are installed, and what additional flags to use when
compiling and linking.

Having additional scripts in your path can confuse software installed via
Homebrew if the config script overrides a system or Homebrew provided
script of the same name. We found the following "config" scripts:

/Library/Frameworks/Python.framework/Versions/2.7/bin/python-config
/Library/Frameworks/Python.framework/Versions/2.7/bin/python2-config
/Library/Frameworks/Python.framework/Versions/2.7/bin/python2.7-config
Warning: You have unlinked kegs in your Cellar
Leaving kegs unlinked can lead to build-trouble and cause brews that depend on
those kegs to fail to run properly once built. Run brew link on these:

jpeg

这个许可问题已经使它不可能使用酿造任何东西,我真的很感激任何建议。


当前回答

首先,使用MacOS Catalina,不再允许更改/usr/local的所有权的基本方法。例如:

$ sudo chown -R "$USER":wheel /usr/local
Password:
chown: /usr/local: Operation not permitted
$ sudo chown -R "$USER" /usr/local
chown: /usr/local: Operation not permitted
$ sudo chown -R $(whoami) /usr/local
chown: /usr/local: Operation not permitted

因此,上面常用的答案不能使用。然而,其次,退一步说,如果主要考虑的是安装或升级Homebrew,而不是想要更改/usr/local本身的权限,那么更改/usr/local的权限可能会太过了(就像用大锤锤钉子一样)。它会影响您的整个机器和其他软件可能也在使用/usr/local。例如,我在/usr/local中有maven和mySQL相关的文件。

一个更精确的解决方案是按照Homebrew GitHub站点上给出的说明安装Homebrew,即

/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)"

它将Homebrew安装在/usr/local中,而不改变/usr/local本身的所有权。相反,Cellar、Caskroom、Frameworks、Homebrew等都安装在/usr/local目录下。在我看来,这似乎是一个更优雅、更精确的解决方案。

其他回答

从得票最多的答案命令不工作的我。

它得到输出:

Chown: /usr/{my_username}dmin:非法用户名

这个命令工作正常(组/usr/local已经是admin):

sudo chown -R $USER /usr/local

其实很简单,执行这个命令: 酿造的医生

它会告诉你该怎么做,来修复权限问题,比如我的例子:

这就是问题所在:

Warning: The following directories are not writable by your user:
/usr/local/share/man/man5
/usr/local/share/man/man7

这就是解决方案:

You should change the ownership of these directories to your user.
  sudo chown -R $(whoami) /usr/local/share/man/man5 /usr/local/share/man/man7

这就解决了我的问题。

sudo chown -R "$USER":admin /Users/$USER/Library/Caches/Homebrew
sudo chown -R "$USER":admin /usr/local

如果你在OSX High Sierra, /usr/local不能再被咀嚼。你可以使用:

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

macOS High Sierra的新命令,因为不可能咀嚼/usr/local:

bash / zsh:

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

鱼:

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

参考:不能chown /usr/local在High Sierra