778

I have uninstalled and installed Homebrew 3 times now because it seems to never allow me to install anything as it denies me permissions at the end of most installations.

As an example I will post this libjpeg download scenario that I'm currently facing.

I try to install libjpeg and get:

$ brew install libjpeg
==> Downloading https://downloads.sf.net/project/machomebrew/Bottles/jpeg-8d.mountain_lion.bottle.1.tar.gz
Already downloaded: /Library/Caches/Homebrew/jpeg-8d.mountain_lion.bottle.1.tar.gz
==> Pouring jpeg-8d.mountain_lion.bottle.1.tar.gz
Warning: Could not link jpeg. Unlinking...
Error: The brew link step did not complete successfully
The formula built, but is not symlinked into /usr/local
You can try again using `brew link jpeg'
Error: Permission denied - /usr/local/opt/jpeg

'brew link jpeg' results in

Error: Permission denied - /usr/local/opt/jpeg

Here is what my brew doctor reads

$ brew doctor
Warning: "config" scripts exist outside your system or Homebrew directories.
./configure scripts often look for *-config scripts to determine if
software packages are installed, and what additional flags to use when
compiling and linking.

Having additional scripts in your path can confuse software installed via
Homebrew if the config script overrides a system or Homebrew provided
script of the same name. We found the following "config" scripts:

/Library/Frameworks/Python.framework/Versions/2.7/bin/python-config
/Library/Frameworks/Python.framework/Versions/2.7/bin/python2-config
/Library/Frameworks/Python.framework/Versions/2.7/bin/python2.7-config
Warning: You have unlinked kegs in your Cellar
Leaving kegs unlinked can lead to build-trouble and cause brews that depend on
those kegs to fail to run properly once built. Run brew link on these:

jpeg

This permission issue has been making it impossible to use brew on anything and I would really appreciate any suggestions.

Paul Rada
  • 19,011
  • 4
  • 15
  • 11

31 Answers31

1079

I was able to solve the problem by using chown on the folder:

sudo chown -R "$USER":admin /usr/local

Also you'll (most probably) have to do the same on /Library/Caches/Homebrew:

sudo chown -R "$USER":admin /Library/Caches/Homebrew

Apparently I had used sudo before in a way that altered my folder permission on /usr/local, from here on forward all installations with brew have proven to be successful.

This answer comes courtesy of gitHub's homebrew issue tracker

xji
  • 7,341
  • 4
  • 40
  • 61
Paul Rada
  • 19,011
  • 4
  • 15
  • 11
  • Thank you for this. Fixed a problem I've had for months and been too lazy to try and fix it. Just been doing sudo brew install ... in the past. But this was exactly what I needed. I'm guessing it's because I was trying to run brew and macports side-by-side for a while (without doing any magical encantation to get them to play nice). – Bane Jun 03 '14 at 12:12
  • 17
    Thanks for this. I also needed to run `sudo chown -R $USER:admin /Library/Caches/Homebrew` to get rid of my permissions issues. – alexpls Jun 15 '14 at 05:23
  • 78
    changing ownership of /usr/local to a specific user is not a solution. It is a terrible hack and a workaround *if* you have a single user system. But then you might as well just chown -R / $USER:$USER – fijiaaron Jan 23 '15 at 04:02
  • 22
    @fijiaaron So what would be a better solution? – juil Jun 16 '15 at 23:27
  • @fijiaaron I agree that it isn't nice, but for all intents and purposes my laptop might as well be a single user system. It's also worth noting that there isn't a `$USER` group in OS X that I can see, by default; the home directory is just set to `staff`. – John Chadwick Jun 18 '15 at 18:19
  • 61
    chowning /usr/local : completely insane solution. Dearly hoping this isn't actually the party line. – John Clements Sep 01 '15 at 22:48
  • 11
    it may be insane but it is what brew itself suggests: `$ brew update Error: The /usr/local directory is not writable. Even if this directory was writable when you installed Homebrew, other software may change permissions on this directory. Some versions of the "InstantOn" component of Airfoil are known to do this. You should probably change the ownership and permissions of /usr/local back to your user account. sudo chown -R $(whoami):admin /usr/local` – remcoder Oct 17 '15 at 18:49
  • 3
    I was always partial to MacPorts, but never had a reason. I never expected to find such a good one to be wary of Homebrew. – hmijail Mar 12 '16 at 09:47
  • 2
    I found I also needed `sudo chown -R "$USER":admin /Users/"$USER"/Library/Logs/Homebrew` – sje397 Mar 30 '16 at 12:28
  • 1
    Will this action affect other users? – nn0p Oct 27 '16 at 16:38
  • 1
    @nn0p yes it will, if you do this, other users don't have install permissions for brew anymore. also other tools doing things in `/usr/local` might get permission problems. – Alexander Oh Jan 09 '17 at 12:46
  • 7
    this answer is wrong if your mac is shared between multiple users... I used this https://gist.github.com/jaibeee/9a4ea6aa9d428bc77925 that change the group permission for all the "admin" group with write access. – Andrea De Gaetano Jan 26 '17 at 09:42
  • 24
    To those who are complaining that this solution will mess up multi-user systems (@fijiaaron, @JohnClements, @hmijail, @Alex)— this exactly why group permissions were inverted.  On macOS, the `admin` group is every admin user (which is every macOS user account user who can `sudo`, among other things), so by running `chown -R …:admin` along with `chmod -R g+w /usr/local` (as suggested by @AndreaDeGaetano), you will be doing nothing wrong here and have zero problems with other users also using `/usr/local`/`brew`. – Slipp D. Thompson Mar 18 '17 at 01:41
  • Not works. got: `chown: /usr/{my_username}dmin: illegal user name`. Here is my solution: https://stackoverflow.com/a/27081770/1698467 – skywinder Jun 13 '17 at 06:55
  • 2
    This solution breaks McAffee, by the way. – Homr Zodyssey Jul 31 '17 at 15:36
  • 1
    Changing ownership og `/usr/local` is no longer requested in the latest brew version. Run `brew update` to update it! – jeerbl Aug 08 '17 at 18:26
  • This helped for MacOs Sierra - also discussed in -https://github.com/Homebrew/brew/issues/2062 – Rishi Aug 31 '17 at 21:06
  • 1
    Note it is incorrect to blame the user (yourself) for somehow having used `sudo` in some way that caused permissions in `/usr/local` to change. You did not. Some package installed from source abused sudo on your behalf during its install. I've yet to find the culprit, but it keeps happening. In reality `sudo` is *evil* and should be banished from the world forever. – Greg A. Woods Sep 08 '17 at 20:31
  • 1
    new OS has a different path for brew cache. If the second command fails, replace it with the home path and run: `sudo chown -R "$USER":admin ~/Library/Caches/Homebrew` – Keng Oct 07 '17 at 17:28
  • For high sierra you cannot use this command any more - you need to use: sudo chown -R $(whoami) $(brew --prefix)/* – Richard Nov 12 '17 at 20:05
  • 4
    For High Sierra users: sudo chown -R $(whoami) $(brew --prefix)/* https://github.com/Homebrew/brew/issues/3228 – Fernando Ferreira Dec 16 '17 at 14:26
  • 3
    Terrible solution!!! I don't get why people upvote this. This will break lots of systems, especially corporate MacBooks. – mitchkman May 17 '18 at 18:42
  • 2
    changing ownership of these directories is fixing for one user and breaking it for the previous owner. And this has 800+ votes? Below there is a better approach which is giving "group" access to users. In my case I use brew with two admin users, so what I did was: sudo chmod -R g+w /usr/local/ – Leonardo Brambilla Jun 18 '18 at 18:42
  • I tried it, it's not permitted to apply the change the whole directory /usr/local but i changed /usr/local/homebrew that's worked fine – Ahmed Wahba Jun 27 '18 at 15:10
  • I had to also had to do `sudo chown -R "$USER":admin /private/tmp` – Chris Habgood Aug 15 '18 at 02:25
  • Can anyone point me to a detailed explanation why using chown is insane? Also, how can I understand why on my older mac brew has not enough permissions and on another, newer - it works fine. Os is same, so two big differences are hardware and, of course, the environment. – queezz Apr 25 '19 at 03:21
  • This answer is wrong. andrewwong97's answer is the correct one. – Jon Ramvi May 12 '19 at 11:43
  • this fixed my issue: sudo chown -R $USER:admin ~/Library/Caches/Homebrew – Uncoke Nov 22 '19 at 10:01
  • Changing the /usr/local permissions sounds like overkill, and besides, is not allowed on MacOS Catalina. See my solution below if your main intention is just to install Homebrew in /usr/local. – auspicious99 Dec 05 '20 at 15:03
  • If the answer is “wrong” or “insane” then surely the solution is to down vote this answer in favour of a better and or more recent solution? Proclaiming it as insane doesn’t really help anybody. – Gavin Apr 05 '21 at 17:28
  • 1
    sudo su , then `chown: /usr/local: Operation not permitted` – Yogi Arif Widodo Mar 31 '22 at 05:02
847

New command for users on macOS High Sierra as it is not possible to chown on /usr/local:

bash/zsh:

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

fish:

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

Reference: Can't chown /usr/local in High Sierra

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
andrewwong97
  • 8,589
  • 1
  • 11
  • 6
  • Might using a blob for everything in $(brew --prefix) be destructive to some directories? I have a MacGPG2 directory that is owned by root and another dot-file as well. – Jahhein Jan 27 '18 at 13:21
  • 3
    Relatedly. For what I was trying to do, I had to `sudo mkdir /usr/local/Frameworks`, followed by the chown command as appears in this answer. – Dan Burton Aug 28 '18 at 21:59
  • I get `Error: Permission denied @ rb_sysopen` when trying to install anything. brew install wget example: Error: Permission denied @ rb_sysopen - /private/tmp/github_api_headers20180921-2313-16tl72c – olefrank Sep 21 '18 at 15:24
  • I also had issue with my XCode version. It was older one and bre doctor showed a complaint about it. The issue resolved after upgrade of XCode. – Anupam Jain Jan 04 '19 at 10:22
  • I followed the following advice via this link and it seemed to work https://flaviocopes.com/npm-fix-missing-write-access-error/ - I was able to add a global package that I previously wasn't able to. – Andy Aug 05 '19 at 14:37
  • Except for that back-tick at the end of the bash command, it works perfectly fine. – Rvy Pandey Jun 03 '20 at 15:37
  • 2
    worked for Mac OS Big Sur too and i still use Rosetta emulator as well for a copy of OS terminal. – Mohammed Ramadan Jul 30 '21 at 09:30
  • Asterisk should not be used at the end of the Command, as it excludes `.git` repo. The correct Command that fixed the stuff is `sudo chown -R $(whoami) $(brew --prefix)/` – Roman Savrulin Jun 28 '23 at 21:32
337

As a first option to whomever lands here like I did, follow whatever this suggests you to do:

brew doctor

It's the safest path, and amongst other things, it suggested me to:

sudo chown -R $(whoami) /usr/local

which solved that permissions issue.

The OP did just that but apparently didn't get the above suggestion; you might, and it's always better to start there, and only then look for non trivial solutions if it didn't help.

Arnaud
  • 17,268
  • 9
  • 65
  • 83
  • 5
    Confirmed this fixes any issue you may be having with permissions as of 05/2017 – Anton Babushkin May 20 '17 at 00:38
  • 4
    Can also confirm that this solves any permission issues and was able to then upgrade my node version with ease - 06/06/2018 - Thanks – Richlewis Jun 06 '18 at 08:53
  • 3
    brew doctor will not find all issues. The issue that I had was /usr/local/Frameworks did not exist and creating that and setting ownership on that fixed it. brew itself did not notice that as an issue. – Joe W Feb 28 '19 at 15:57
  • 10
    I get `chown: /usr/local: Operation not permitted` doesn't work as of 5th July 2019 – tavalendo Jul 05 '19 at 06:01
  • @user102859 brew doctor still works ;) The specific action suggested at the time may or may not work in a given time/configuration but it is irrelevant, this is just meant as a reminder to start with the doctor. – Arnaud Jul 05 '19 at 06:09
  • 2
    The hint with the doctor is maybe one of the best hints here, because it fixes (or helps to fix) different issues at any time! – ecth Sep 12 '19 at 12:28
  • 1
    For the "Operation not permitted" on my new Mac OS Catalina V10.15.1, I ended up doing `sudo su` first and then `cd /usr/local/`, then `sh-3.2# chown -R :admin homebrew` – kisna Jan 21 '20 at 02:56
  • 3
    As per `https://github.com/Homebrew/brew/issues/3228`, `sudo chown -R $(whoami) $(brew --prefix)/*` is the way to do with HighSierra and above. – Vivek V K Oct 19 '20 at 10:36
  • 1
    Confirmed this worked for me. Also found a number other issues as well. – Craig B Oct 31 '22 at 18:40
  • 1
    Just running brew doctor was enough for me. Thanks. I was installing ffmpeg using brew and after installation it suggested to give current user access to few paths like /opt/homebrew and other I don't remember and I just ran the suggested commands without any second thoughts and I started getting weird permission issues even if I type 'brew' command. Brew doctor to the rescue! cheers. – watney Aug 10 '23 at 18:55
118

If you're on OSX High Sierra, /usr/local can no longer be chown'd. You can use:

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

Carolus
  • 477
  • 4
  • 16
Richard
  • 1,559
  • 2
  • 12
  • 15
  • 2
    Thanks. Saved me! – Matthias Apr 25 '18 at 15:33
  • 4
    I found that $(brew --prefix) just gave me /usr/local, which High Sierra insisted I couldn't change the permissions to...but since brew wanted permissions to "/usr/local/Frameworks" in my instance, I was able to use "$(brew --prefix)/Frameworks" instead, and "brew link python@2" worked fine for me after that. – alpheus Aug 10 '18 at 16:38
  • 2
    All Mac users with multiple users, use this! – Erik Nguyen Jan 31 '19 at 13:23
  • 1
    Thanks am on OSX High Sierra, and apparently we cannot chown the /user/local anymore as in prev versions of MAC OSX. This worked for me! – Jose Mhlanga Jun 05 '20 at 10:33
  • This finally resolved the issue for me on Big Sur. I have two user accounts on my Mac and it was causing an issue. – mrkot Dec 21 '20 at 16:40
44

This worked for me in 2022 on an M1 Mac with Monterey

sudo chown -R $(whoami) $(brew --prefix)/*
timgavin
  • 4,972
  • 4
  • 36
  • 48
36

I didn't want to muck around with folder permissions yet so I did the following:

brew doctor
brew upgrade
brew cleanup

I was then able to continue installing my other brew formula successfully.

Anthony To
  • 2,193
  • 2
  • 21
  • 29
32

I did not have the /usr/local/Frameworks folder, so this fixed it for me

sudo mkdir -p /usr/local/Frameworks
sudo chown -R $(whoami) /usr/local/Frameworks

The first line creates a new Frameworks folder for homebrew (brew) to use. The second line gives that folder your current user permissions, which are sufficient.

Used commands are as follows:

mkdir - make directories [-p no error if existing, make parent directories as needed]

chown - change file owner and group [-R operate on files and directories recursively]

whoami - print effective userid

I have OSX High Sierra

Community
  • 1
  • 1
Karl Johan Vallner
  • 3,980
  • 4
  • 35
  • 46
28

I had this issue .. A working solution is to change ownership of /usr/local to current user instead of root by:

  sudo chown -R $(whoami):admin /usr/local

But really this is not a proper way. Mainly if your machine is a server or multiple-user.

My suggestion is to change the ownership as above and do whatever you want to implement with Brew .. ( update, install ... etc ) then reset ownership back to root as:

  sudo chown -R root:admin /usr/local

Thats would solve the issue and keep ownership set in proper set.

Maher Abuthraa
  • 17,493
  • 11
  • 81
  • 103
15

Command from top-voted answer not work for me.

It got output:

chown: /usr/{my_username}dmin: illegal user name

This command works fine (group for /usr/local was admin already):

sudo chown -R $USER /usr/local
Community
  • 1
  • 1
skywinder
  • 21,291
  • 15
  • 93
  • 123
15

This worked for me:

sudo chown -R "$USER":admin /usr/local/Cellar/*
brew cleanup
Cat
  • 171
  • 1
  • 3
12

If you would like a slightly more targeted approach than the blanket chown -R, you may find this fix-homebrew script useful:

#!/bin/sh

[ -e `which brew` ] || {
    echo Homebrew doesn\'t appear to be installed.
    exit -1
}

BREW_ROOT="`dirname $(dirname $(which brew))`"
BREW_GROUP=admin
BREW_DIRS=".git bin sbin Library Cellar share etc lib opt CONTRIBUTING.md README.md SUPPORTERS.md"

echo "This script will recursively update the group on the following paths"
echo "to the '${BREW_GROUP}' group and make them group writable:"
echo ""

for dir in $BREW_DIRS ; do {
    [ -e "$BREW_ROOT/$dir" ] && echo "    $BREW_ROOT/$dir "
} ; done

echo ""
echo "It will also stash (and clean) any changes that are currently in the homebrew repo, so that you have a fresh blank-slate."
echo ""

read -p 'Press any key to continue or CTRL-C to abort.'

echo "You may be asked below for your login password."
echo ""

# Non-recursively update the root brew path.
echo Updating "$BREW_ROOT" . . .
sudo chgrp "$BREW_GROUP" "$BREW_ROOT"
sudo chmod g+w "$BREW_ROOT"

# Recursively update the other paths.
for dir in $BREW_DIRS ; do {
    [ -e "$BREW_ROOT/$dir" ] && (
        echo Recursively updating "$BREW_ROOT/$dir" . . .
        sudo chmod -R g+w "$BREW_ROOT/$dir"
        sudo chgrp -R "$BREW_GROUP" "$BREW_ROOT/$dir"
    )
} ; done

# Non-distructively move any git crud out of the way
echo Stashing changes in "$BREW_ROOT" . . .
cd $BREW_ROOT
git add .
git stash
git clean -d -f Library

echo Finished.

Instead of doing a chmod to your user, it gives the admin group (to which you presumably belong) write access to the specific directories in /usr/local that homebrew uses. It also tells you exactly what it intends to do before doing it.

  • 1
    Note that some of the paths seem to have changed a bit so you may have to chgrp and chmod a few more directories but I still prefer this over the chown everything to your user approach! – ashirley Oct 20 '17 at 09:35
8

I resolved my issue with these commands:

sudo mkdir /usr/local/Cellar
sudo mkdir /usr/local/opt
sudo chown -R $(whoami) /usr/local/Cellar
sudo chown -R $(whoami) /usr/local/opt
hardc0der
  • 449
  • 2
  • 7
  • 13
  • 1
    Thanks! Thats the only thing that helped on `Mac OS 10.13.4` In my case I had to create `sudo mkdir /usr/local/Frameworks` and `sudo chown -R $(whoami) /usr/local/Frameworks` to be able to link python! – A1m May 14 '18 at 01:15
8

In my case the /usr/local/Frameworks didn't even exist, so I did:

sudo mkdir /usr/local/Frameworks
sudo chown -R $(whoami) /usr/local/Frameworks

And then everything worked as expected.

8

Firstly, with MacOS Catalina, the basic ways to change the ownership of /usr/local are no longer allowed. For example:

$ sudo chown -R "$USER":wheel /usr/local
Password:
chown: /usr/local: Operation not permitted
$ sudo chown -R "$USER" /usr/local
chown: /usr/local: Operation not permitted
$ sudo chown -R $(whoami) /usr/local
chown: /usr/local: Operation not permitted

Hence, the popular answers above cannot be used. Secondly, however, taking a step back, if the main concern is to install or upgrade Homebrew, rather than wanting to change the permissions for /usr/local per se, then it may be overkill (like taking a sledgehammer to hammer a nail) to change the permissions for /usr/local. It affects your whole machine and other software may also be using /usr/local. For example, I have files related to maven and mySQL in /usr/local.

A more precise solution is to follow the instructions to install Homebrew, given at the Homebrew GitHub site, namely

/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)"

which installs Homebrew inside /usr/local without changing ownership of /usr/local itself. Instead, Cellar, Caskroom, Frameworks, Homebrew, etc. are installed inside /usr/local. This seems to be a more elegant, precise solution in my opinion.

auspicious99
  • 3,902
  • 1
  • 44
  • 58
  • 1
    I am on macOS Big Sur and was trying to install brew (after a format) this is the only method that seemed to work. All the above methods kept giving me `permission denied`. – manuignatius Dec 06 '20 at 01:53
  • I tried that line but still got the error `error: unable to unlink old 'Library/Homebrew/cmd/vendor-install.sh': Permission denied`. – moiaussi06 Jan 04 '21 at 17:26
7

This solved the issue fore me.

sudo chown -R "$USER":admin /Users/$USER/Library/Caches/Homebrew
sudo chown -R "$USER":admin /usr/local
Fardin Abdi
  • 1,284
  • 15
  • 20
  • 2
    This solves this issue but I'd undo this step after successfully linking. Just because of security reasons. – o0x258 Sep 11 '17 at 16:48
7

For a multiuser Mac, this worked for me:

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

All of these suggestions may work. In the latest version of brew doctor, better suggestions were made though.

Firstly - fix the mess you have probably already made of /usr/local by running this in the command line:

sudo chown -R root:wheel /usr/local

Then take ownership of the paths that should be specifically for this user:

sudo chown -R $(whoami) /usr/local/lib /usr/local/sbin /usr/local/var /usr/local/Frameworks /usr/local/lib/pkgconfig /usr/local/share/locale

All of this information is available if you run sudo brew update and then read all of the warnings and errors you will run into...

Luka Kerr
  • 4,161
  • 7
  • 39
  • 50
Max Dercum
  • 87
  • 1
  • 5
  • Setting the ownership of everything in /usr/local to root:wheel is dangerous and unnecessary. The relevant path is /usr/local/Cellar – ben26941 Nov 28 '16 at 09:18
  • 1
    you dont need to touch those permissions, unless you have .. say already gone ahead and taken ownership of them for your development user - or in the case where brew has already mangled them because it did an install with sudo. brew its self recommends this fix in that case - which i think is a lot less dangerous than leaving the sudo mess behind. – Max Dercum Dec 01 '16 at 05:02
  • 1
    Could you provide a link to the brew recommendation then? – ben26941 Dec 01 '16 at 10:18
  • 1
    Best answer. It worked after I did a Migration from another Mac. – BuffMcBigHuge Jul 08 '17 at 02:28
6

For me, it worked after

brew doctor

Change permission commands resulted in another error

chown: /usr/local: Operation not permitted

Krishnadas PC
  • 5,981
  • 2
  • 53
  • 54
5

On MacOS Mojave, I did not have permission to chown the /usr/local folder either (sudo chown -R "$USER":admin /usr/local).

sudo chown -R "$USER":admin /usr/local/* did work for me however, altering the permissions of everything within the local folder.

Hopefully this will help others with the same issue.

paddotk
  • 1,359
  • 17
  • 31
  • Worked for me on Catalina. Until I did this, I couldn't install brew at all. After I did it, it was badda-bing badda-boom. – matt Nov 28 '20 at 17:40
4

There's a killer script on github that fixes perms on /usr/local and brew directories to be accessible by anyone who is a member of the 'admin' group.

https://gist.github.com/jaibeee/9a4ea6aa9d428bc77925

This is a better solution than the chosen answer, since if you chown the /usr/local/___ directories to $USER, then you break any other admin users of homebrew on that machine.

Here are the guts of the script at the time I posted this:

chgrp -R admin /usr/local
chmod -R g+w /usr/local

chgrp -R admin /Library/Caches/Homebrew
chmod -R g+w /Library/Caches/Homebrew

chgrp -R admin /opt/homebrew-cask
chmod -R g+w /opt/homebrew-cask
TheProletariat
  • 916
  • 2
  • 11
  • 23
4

Actually it's really simple, execute this command: brew doctor

And it will tell you what to do, to fix permission issues, for example in my case:

This was the problem:

Warning: The following directories are not writable by your user:
/usr/local/share/man/man5
/usr/local/share/man/man7

And this was the solution:

You should change the ownership of these directories to your user.
  sudo chown -R $(whoami) /usr/local/share/man/man5 /usr/local/share/man/man7
Arsalan Mehmood
  • 1,432
  • 1
  • 15
  • 26
3

I'm on Catalina and I got this error:

touch: /usr/local/Homebrew/.git/FETCH_HEAD: Permission denied
touch: /usr/local/Homebrew/Library/Taps/homebrew/homebrew-cask/.git/FETCH_HEAD: Permission denied
fatal: Unable to create '/usr/local/Homebrew/.git/index.lock': Permission denied
fatal: Unable to create '/usr/local/Homebrew/.git/index.lock': Permission denied

I only needed to chown the Homebrew directory

sudo chown -R "$USER":admin /usr/local/Homebrew
Bilal
  • 2,883
  • 5
  • 37
  • 60
2

uninstall brew & re-install with the below command to ensure the linking to the brew github and associated permissions to the local folder work correctly:

/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

This worked perfectly. No mucking around with permissions myself, just reinstalled Homebrew and it works!

source: https://gist.github.com/irazasyed/7732946#gistcomment-2298740

Abid Khairy
  • 1,198
  • 11
  • 9
  • 1
    The terminal command in the link is `sudo chown -R $(whoami) $(brew --prefix)/*` – Kamil.S Nov 04 '21 at 09:37
  • @Kamil.S oh that must be the github issue title, try to scroll down to aether2501 comment – Abid Khairy Nov 08 '21 at 10:28
  • 1
    Ruby has now been disabled for this and you need to use the bash command version as indicated in the error i got: `Error: The Ruby Homebrew installer is now disabled and has been rewritten in Bash. Please migrate to the following command: /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"` – EeKay Oct 07 '22 at 08:02
1
cd /usr/local && sudo chown -R $(whoami) bin etc include lib sbin share var opt Cellar Frameworks
Girish Gupta
  • 1,241
  • 13
  • 27
1

If you happen to have multiple accounts on your mac, chances are, your current account belongs to different user group as the primary account that originally owned /usr/local meaning that none of the solutions above will work.

You can check that by trying to ls -la /usr/local and see what user and group that have permissions to write on the directory. In my case it was root wheel. It may be root admin.

I solved it by adding the current user to the group that primary account has by using the following command.

sudo dseditgroup -o edit -a $(whoami) -t user admin
sudo dseditgroup -o edit -a $(whoami) -t user wheel

There after it worked like a charm. Hopefully it helps someone out there.

0

If you don't have the latest Homebrew: I "fixed" this in the past by forcing Homebrew to run as root, which could only be done by changing the ownership of the Homebrew executables to root. At some point, they removed this feature.

And I know they'll give lots of warnings saying it shouldn't run as root, but c'mon, it doesn't work properly otherwise.

sudo
  • 5,604
  • 5
  • 40
  • 78
0

I tried everything on this page, I ended up using this solution:

brew uninstall --force brew-cask; brew untap $tap_name; brew update; brew cleanup; brew cask cleanup;

My situation was similar to the OP, however my issue was specifically caused by running sudo with brew cask, and then getting my password incorrect. After this, I was stuck with permissions preventing the installation.

AlphaG33k
  • 1,588
  • 1
  • 12
  • 24
0

To resolve errors for Brew permissions on folder run

brew prune

This will resolve the issues & we don't have to chown any directories.

Catto
  • 6,259
  • 2
  • 52
  • 55
0

In my case, I has having problems removing and reinstalling SaltStack.

After running:

ls -lah /usr/local/Cellar/salt/

I noticed that the group owner was "staff". (BTW, I'm running macOS Mojave version 10.14.3.) The staff group could be related to my workplace configuration, but I don't really know. Regardless, I preserved the group to prevent myself from breaking anything further.

I then ran:

sudo chown -R "$USER":staff /usr/local/Cellar/salt/

After that, I was successfully able to remove it with this command (not as root):

brew uninstall --force salt
devinbost
  • 4,658
  • 2
  • 44
  • 57
0

I used these two commands and saved my problem

sudo chown -R $(whoami) /usr/local

sudo chown -R $(whoami) /usr/local/etc/bash_completion.d /usr/local/lib/python3.7/site-packages /usr/local/share/aclocal /usr/local/share/locale /usr/local/share/man/man7 /usr/local/share/man/man8 /usr/local/share/zsh /usr/local/share/zsh/site-functions /usr/local/var/homebrew/locks
Marco Aprea
  • 349
  • 2
  • 13
-5

try also executing this command

sudo chmod +t /tmp

bashar
  • 1