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

我想使用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

您还可以看到相关的github问题here

转载注明原文:macos – 安装Carthage时出现“错误:无法锁定配置文件.git/config:权限被拒绝”的错误 - 代码日志