58

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.

bfontaine
  • 18,169
  • 13
  • 73
  • 107
Saeid
  • 1,996
  • 4
  • 27
  • 44

7 Answers7

135

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 and above, Run this command instead:

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

You can also see the related github issues here

Thomas Easo
  • 3,457
  • 3
  • 21
  • 32
Kazunori Takaishi
  • 2,268
  • 1
  • 15
  • 27
82

In High Sierra, run the command:

sudo chown -R $(whoami) $(brew --prefix)/*
Ru Chern Chong
  • 3,692
  • 13
  • 33
  • 43
Safa Ozturk
  • 821
  • 1
  • 6
  • 3
18

This worked for me : macOS Catalina 10.15.1

sudo chown -R $(whoami):admin /usr/local/* && sudo chmod -R g+rwx /usr/local/*
Community
  • 1
  • 1
Olufemi
  • 346
  • 2
  • 9
  • 1
    Welcome to Stack Overflow! While this command may answer the question, it is better to include some context, explaining how it works and when to use it. Code-only answers tend to be less useful in the long run. See [How do I write a good answer?](https://stackoverflow.com/help/how-to-answer) for some more info. – Mark Ormesher Dec 17 '19 at 08:04
15

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

Saeid
  • 1,996
  • 4
  • 27
  • 44
2

You can use this also instead sudo chown -R $USER $(brew --prefix)/*

2

I have macOS Catalina 10.15.1 after hours (like always) this worked.

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

1

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