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

蹲街弑〆低调 提交于 2019-11-29 05:54:00

问题


I want to install carthage on my Mac OS using brew install carthage command. However, I get the following error:

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.

I also get the following error when I used 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.

Can you let me know what is the problem. Thanks in advance.


回答1:


Check for the permissions on these files.

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

If you don't have the permissions, run

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

In High Sierra, Run this command instead:

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

You can also see the related github issues here




回答2:


In High Sierra, run the command:

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



回答3:


In my case this command working:

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

However, there is also an easier way of installing Carthage instead of commands line way. It is enough to download the latest package from this link and install it in a wizard way on you Mac.

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




回答4:


I have High Sierra and only this worked for me.

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


来源:https://stackoverflow.com/questions/49282002/error-of-error-could-not-lock-config-file-git-config-permission-denied-occu

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!