安装Carthage时出现“错误:无法锁定配置文件.git / config:权限被拒绝”的错误

58

我想使用 brew install carthage 命令在我的 Mac OS 上安装 Carthage。然而,我收到了以下错误:

touch: /usr/local/Homebrew/.git/FETCH_HEAD: Permission denied
touch: /usr/local/Homebrew/Library/Taps/caskroom/homebrew-cask/.git/FETCH_HEAD: Permission denied
touch: /usr/local/Homebrew/Library/Taps/dart-lang/homebrew-dart/.git/FETCH_HEAD: Permission denied
touch: /usr/local/Homebrew/Library/Taps/homebrew/homebrew-core/.git/FETCH_HEAD: Permission denied
fatal: Unable to create '/usr/local/Homebrew/.git/index.lock': Permission denied
error: could not lock config file .git/config: Permission denied
Warning: carthage 0.26.2 is already installed, it's just not linked.
You can use `brew link carthage` to link this version.

当我使用sudo brew install carthage时,我也遇到了以下错误:

Translated version:

当我使用sudo brew install carthage时,我也遇到了以下错误:

Error: Running Homebrew as root is extremely dangerous and no longer supported.
As Homebrew does not drop privileges on installation you would be giving all
build scripts full access to your system.

你能告诉我问题出在哪里吗?先谢谢了。


3
请运行 brew doctor 命令,按照其建议进行处理,然后再尝试一次。 - bfontaine
7个回答

136

检查这些文件的权限。

ls -l /usr/local/Homebrew/.git/FETCH_HEAD
ls -l /usr/local/Homebrew/Library/Taps/caskroom/homebrew-cask/.git/FETCH_HEAD
ls -l /usr/local/Homebrew/Library/Taps/dart-lang/homebrew-dart/.git/FETCH_HEAD
ls -l /usr/local/Homebrew/Library/Taps/homebrew/homebrew-core/.git/FETCH_HEAD

如果你没有权限,请运行

sudo chown -R $(whoami):admin /usr/local/* && sudo chmod -R g+rwx /usr/local/*

在 High Sierra 及更高版本中,请运行以下命令:

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

您还可以在此处查看相关的Github问题 here


8
操作不允许。 - Umit Kaya
21
在 macOS Mojave (10.14) 上,我需要运行以下命令:sudo chown -R $(whoami):admin /usr/local/* && sudo chmod -R g+rwx /usr/local/* - Nic
1
我遇到了同样的问题,这个方法对我非常有效,谢谢@Kazunori Takaishi。 - aramis
sudo chown -R $(whoami) $(brew --prefix)/* 运行得非常好。 - Tunvir Rahman Tusher

83

在 High Sierra 中运行以下命令:

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

18

这对我有效:

macOS Catalina 10.15.1

sudo chown -R $(whoami):admin /usr/local/* && sudo chmod -R g+rwx /usr/local/*

1
欢迎来到 Stack Overflow!虽然这个命令可能会回答问题,但最好还是包含一些上下文,解释它的工作原理以及何时使用它。仅有代码的答案在长期内往往不太有用。请参阅 如何编写一个好的答案? 获取更多信息。 - Mark Ormesher

15

在我的情况下,此命令有效:

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

然而,安装Carthage的更简单方法是通过下载最新的软件包并在Mac上以向导方式安装,而不是通过命令行方式。

https://github.com/Carthage/Carthage/releases


1
@doapydave: 很高兴听到这个好消息 :) - Saeid

2
您也可以使用以下命令: sudo chown -R $USER $(brew --prefix)/*

2

我使用的是macOS Catalina 10.15.1,这段代码可以让它正常运行:

sudo chown -R $(whoami):admin /usr/local/* && sudo chmod -R g+rwx /usr/local/*

请注意保留HTML标签。


1
我有 High Sierra 操作系统,只有这个方法对我有效。
1. sudo chown -R $(whoami):admin /usr/local/* && sudo chmod -R g+rwx /usr/local/*
在安装 brew 前不应该使用 sudo,正确的命令是
2. brew install mysql

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