如何修复homebrew权限问题?

787

我已经卸载和安装了三次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读取的内容

$ 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,希望能得到任何建议。

32个回答

4

其实很简单,执行以下命令:brew doctor

它会告诉你该怎么做来解决权限问题,例如像我这种情况:

这是问题所在:

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

3

我在使用Catalina操作系统时遇到了这个错误:

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

1
这对我来说是答案。 - jaycarleton

2

1
链接中的终端命令是 sudo chown -R $(whoami) $(brew --prefix)/* - Kamil.S
@Kamil.S 噢,那一定是Github的问题标题,请尝试向下滚动到aether2501的评论。 - Abid Khairy
1
Ruby 现已被禁用,您需要使用错误中指示的 bash 命令版本:错误:Ruby Homebrew 安装程序现已被禁用,并已在 Bash 中重写。请迁移到以下命令: /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)" - EeKay

1
cd /usr/local && sudo chown -R $(whoami) bin etc include lib sbin share var opt Cellar Frameworks

1
如果您在Mac上有多个帐户,那么很可能您当前的帐户属于与最初拥有/usr/local的主帐户不同的用户组,这意味着上述任何解决方案都将无法起作用。
您可以通过尝试ls -la /usr/local来检查,看看哪个用户和组具有写入该目录的权限。 在我的情况下,它是root wheel。它也可能是root admin
我通过使用以下命令将当前用户添加到主帐户所拥有的组中来解决了这个问题。
sudo dseditgroup -o edit -a $(whoami) -t user admin
sudo dseditgroup -o edit -a $(whoami) -t user wheel

之后它就像魔法一样运行了。希望能帮到某个人。


换句话说,你刚刚将普通用户提升为了管理员用户? - hmijail

0

如果您没有最新的Homebrew:过去我曾通过强制Homebrew以root身份运行来“修复”此问题,这只能通过将Homebrew可执行文件的所有权更改为root来完成。但是在某个时候,他们删除了此功能。

我知道他们会发出很多警告,说它不应该以root身份运行,但是,拜托,否则它就无法正常工作。


0

解决Brew权限文件夹运行的错误:

brew prune

这将解决问题,我们无需更改任何目录的所有权。


1
这个不再起作用了,现在你需要执行 brew cleanup --prune-prefix - Sliq

0

我们不能改变 /usr/local 文件夹本身的权限,但是我们可以改变 /usr/local/ 目录下的文件夹的写入权限。

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

0
我试过这页上的所有方法,最后使用了以下解决方案:
brew uninstall --force brew-cask; brew untap $tap_name; brew update; brew cleanup; brew cask cleanup;
我的情况与原帖类似,但我的问题是在使用sudo和brew cask时输入了错误的密码。此后,我被权限问题卡住了安装过程。

0
在我的情况下,我遇到了卸载和重新安装SaltStack的问题。
运行以下命令后:
ls -lah /usr/local/Cellar/salt/

我注意到群组所有者是“staff”。(顺便说一下,我正在运行macOS Mojave版本10.14.3。)Staff组可能与我的工作场所配置有关,但我并不真正知道。无论如何,我保留了该组以防止自己进一步破坏任何东西。

然后我运行了:

sudo chown -R "$USER":staff /usr/local/Cellar/salt/

之后,我成功地使用以下命令(非 root 用户)将其删除:

brew uninstall --force salt

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接