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

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


当前回答

卸载brew并使用以下命令重新安装,以确保到brew github的链接和本地文件夹的相关权限正常工作:

ruby / usr / bin / e,“美元(卷毛-fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)”

这很有效。我自己没有权限,只是重新安装了Homebrew,它可以工作!

来源:https://gist.github.com/irazasyed/7732946 # gistcomment - 2298740

其他回答

如果您没有最新的Homebrew:我在过去通过强制Homebrew以根用户身份运行来“修复”这个问题,这只能通过将Homebrew可执行文件的所有权更改为根用户来实现。在某种程度上,他们删除了这个功能。

我知道他们会给出很多警告,说它不应该以根目录运行,但算了吧,否则它就不能正常工作。

如果你的mac上碰巧有多个帐户,那么很可能你当前的帐户属于不同的用户组,而最初拥有/usr/local的主要帐户意味着上述解决方案都不起作用。

您可以通过尝试ls -la /usr/local来检查,并查看哪些用户和组有权限对该目录进行写操作。 在我的情况下,它是根轮。它可能是根管理员。

我通过使用以下命令将当前用户添加到主帐户的组来解决这个问题。

sudo dseditgroup -o edit -a $(whoami) -t user admin
sudo dseditgroup -o edit -a $(whoami) -t user wheel

在那之后,它就像魔法一样有效。希望它能帮助到一些人。

github上有一个杀手级脚本,可以修复/usr/local和brew目录上的烫发,使任何“admin”组的成员都可以访问。

https://gist.github.com/jaibeee/9a4ea6aa9d428bc77925

这是一个比选择的答案更好的解决方案,因为如果你把/usr/local/___目录改为$USER,那么你就破坏了那台机器上任何其他homebrew的管理用户。

以下是我发布这篇文章时脚本的核心内容:

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

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

chgrp -R admin /opt/homebrew-cask
chmod -R g+w /opt/homebrew-cask

如果你想要一个比毯子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目录下。在我看来,这似乎是一个更优雅、更精确的解决方案。