22

When I run the following command in my terminal:

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

I get an error:

/usr/local/Cellar is not writable. You should change the
ownership and permissions of /usr/local/Cellar back to your
user account:
sudo chown -R $(whoami) /usr/local/Cellar

Failed during: /usr/local/bin/brew update --force

I went through similar posts on S.O and all of them had the following commands as answer,so I ran the following commands in the terminal:

  1. sudo chown -R $tejas /usr/local/Cellar
  2. sudo chown -R $tejas:admin /usr/local/Cellar
  3. sudo chown -R $tejas /usr/local
  4. sudo chown -R $tejas:admin /usr/local

I ran the installation command after all above four command but it still gives me the error. Can someone please help me fix this. Thank you.

Musen
  • 1,244
  • 11
  • 23

6 Answers6

19

As said in the comments, just do (without any substitution):

sudo chown -R $(whoami) /usr/local/Cellar
Rexcirus
  • 2,459
  • 3
  • 22
  • 42
18

I had exactly same issue. I was trying to reset the permissions but some packages weren't able to install anyway. Re-installing the Homebrew solved this for me:

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

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

Roman86
  • 1,990
  • 23
  • 22
9

Reset the permissions of /usr/local and Homebrew's caches to the current user:

sudo chown -R $USER:admin /usr/local /Library/Caches/Homebrew
Lemaitre Cedric
  • 139
  • 2
  • 7
1

I got the same issue on MacOS when install GoAccess:

Error: /usr/local/Cellar is not writable. You should change the
ownership and permissions of /usr/local/Cellar back to your
user account:
  sudo chown -R $(whoami) /usr/local/Cellar
Error: The following directories are not writable by your user:
/usr/local/Cellar
/usr/local/share/zsh
/usr/local/share/zsh/site-functions

I fixed it by run following command:

 sudo chown -R $(whoami) /usr/local/Cellar /usr/local/share/zsh /usr/local/share/zsh/site-functions
Nham Nguyen
  • 533
  • 4
  • 4
1

Method 1: This one might work on older operating systems, as it set permission to directory:

 sudo chown -R $USER /usr/local/Cellar

Method 2. On newer system can't set permission on the directory istelf but there's a method to force adding permission to all children folders by using wilcard(asterisk) '*', (of course a bit dangerous?).

sudo chown -R $USER /usr/local/Cellar/*

Method 3: Using prefix for brew (working from >=High Sierra)

sudo chown -R $USER $(brew --prefix)/*
devzom
  • 676
  • 1
  • 9
  • 19
0

with the help of @Lemaitre Cedric and @Rexcirus ... I fixed my issue.

sudo chown -R $USER:admin /usr/local /Library/Caches/Homebrew
sudo chown -R $(whoami) /usr/local/Cellar
Tushar Pandey
  • 4,557
  • 4
  • 33
  • 50