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

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


当前回答

如果你想要一个比毯子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中特定目录的写权限授予管理组(您可能属于该组)。它还会在执行之前准确地告诉你它打算做什么。

其他回答

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

它得到输出:

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

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

sudo chown -R $USER /usr/local

这招对我很管用:

sudo chown -R "$USER":admin /usr/local/Cellar/*
brew cleanup

我尝试了这页上的所有方法,最终使用了这个解决方案:

酿造卸载-强制酿造桶;取消$tap_name;酿造更新;啤酒清理;酿造桶清理;

我的情况与OP类似,但是我的问题是由使用酿造桶运行sudo引起的,然后让我的密码不正确。在此之后,我被阻止安装的权限所困扰。

这就解决了我的问题。

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

我有这个问题… 一个可行的解决方案是更改/usr/local的所有权 将root用户改为当前用户:

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

但实际上这不是一个正确的方法。主要是当您的机器是服务器或多用户时。

我的建议是像上面一样改变所有权,做任何你想用Brew实现的事情。更新,安装…等等),然后将所有权重置回根:

  sudo chown -R root:admin /usr/local

这将解决问题,并保持所有权设置在适当的集合。