Error of "error: could not lock config file .git/config: Permission denied" occurs while installing Carthage

Error of "error: could not lock config file .git/config: Permission denied" occurs while installing Carthage

我想使用 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时也出现了以下错误:

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.

你能告诉我问题是什么吗?提前致谢。

检查这些文件的权限。

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

在 High Sierra 中,运行 命令:

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

在我的例子中,这个命令有效:

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

但是,除了命令行方式之外,还有一种更简单的方式来安装 Carthage。从这个 link 下载最新的软件包并以向导的方式安装它就足够了 Mac.

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

我有 High Sierra,只有这个对我有用。

1. sudo chown -R $(whoami):admin /usr/local/* && sudo chmod -R g+rwx /usr/local/*
you should not write sudo before brew the right command is 
2. brew install mysql

你也可以用这个代替 sudo chown -R $USER $(brew --prefix)/*

这对我有用: macOS 卡特琳娜 10.15.1

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

下班后我安装了 macOS Catalina 10.15.1(一如既往),这很有效。

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