我已经卸载和安装了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

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


当前回答

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

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

这就是问题所在:

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

其他回答

如果你想要一个比毯子chown -R更有针对性的方法,你可能会发现这个fix-homebrew脚本很有用:

#!/bin/sh

[ -e `which brew` ] || {
    echo Homebrew doesn\'t appear to be installed.
    exit -1
}

BREW_ROOT="`dirname $(dirname $(which brew))`"
BREW_GROUP=admin
BREW_DIRS=".git bin sbin Library Cellar share etc lib opt CONTRIBUTING.md README.md SUPPORTERS.md"

echo "This script will recursively update the group on the following paths"
echo "to the '${BREW_GROUP}' group and make them group writable:"
echo ""

for dir in $BREW_DIRS ; do {
    [ -e "$BREW_ROOT/$dir" ] && echo "    $BREW_ROOT/$dir "
} ; done

echo ""
echo "It will also stash (and clean) any changes that are currently in the homebrew repo, so that you have a fresh blank-slate."
echo ""

read -p 'Press any key to continue or CTRL-C to abort.'

echo "You may be asked below for your login password."
echo ""

# Non-recursively update the root brew path.
echo Updating "$BREW_ROOT" . . .
sudo chgrp "$BREW_GROUP" "$BREW_ROOT"
sudo chmod g+w "$BREW_ROOT"

# Recursively update the other paths.
for dir in $BREW_DIRS ; do {
    [ -e "$BREW_ROOT/$dir" ] && (
        echo Recursively updating "$BREW_ROOT/$dir" . . .
        sudo chmod -R g+w "$BREW_ROOT/$dir"
        sudo chgrp -R "$BREW_GROUP" "$BREW_ROOT/$dir"
    )
} ; done

# Non-distructively move any git crud out of the way
echo Stashing changes in "$BREW_ROOT" . . .
cd $BREW_ROOT
git add .
git stash
git clean -d -f Library

echo Finished.

它不会对用户执行chmod操作,而是将homebrew使用的/usr/local中特定目录的写权限授予管理组(您可能属于该组)。它还会在执行之前准确地告诉你它打算做什么。

首先,使用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目录下。在我看来,这似乎是一个更优雅、更精确的解决方案。

我在卡特琳娜,我得到了这个错误:

touch: /usr/local/Homebrew/.git/FETCH_HEAD: Permission denied
touch: /usr/local/Homebrew/Library/Taps/homebrew/homebrew-cask/.git/FETCH_HEAD: Permission denied
fatal: Unable to create '/usr/local/Homebrew/.git/index.lock': Permission denied
fatal: Unable to create '/usr/local/Homebrew/.git/index.lock': Permission denied

我只需要把Homebrew目录翻个遍

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

对于像我一样降落在这里的人来说,第一选择是,按照这个建议去做:

brew doctor

这是最安全的方法,除此之外,它还建议我:

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

这解决了权限问题。

OP这样做了,但显然没有得到上述建议;你可能会,从这里开始总是更好的,然后再寻找非平凡解如果它没有帮助的话。

所有这些建议都可能奏效。在最新版本的brew doctor中,有了更好的建议。

首先-通过在命令行中运行这个命令来修复你可能已经造成的/usr/local混乱:

sudo chown -R root:wheel /usr/local

然后获取路径的所有权,应该专门为这个用户:

sudo chown -R $(whoami) /usr/local/lib /usr/local/sbin /usr/local/var /usr/local/Frameworks /usr/local/lib/pkgconfig /usr/local/share/locale

所有这些信息都是可用的,如果你运行sudo brew update,然后阅读所有的警告和错误,你会遇到…