135

I am getting issues with permissions in Homebrew: After I installed Node and tried to install npm using the curl command Homebrew tells you to use, it would fail due to EACCESS errors. I checked the node folder and the permissions were a) unowned by a user (I had to chown it) and b) Had no write permissions (I had to chmod 755 it).

I've fixed the issue with NPM, but I had to run its install script as sudo (which is bad!).

I assume I must have installed Homebrew as root or something similar. I am hoping that reinstallation will fix it, but I can't find a source on how to reinstall Homebrew.

When I rerun the installer in Terminal I get:

/usr/local/.git already exists!
AndrewKS
  • 3,603
  • 2
  • 24
  • 33
  • I made same mistake of running brew with root, manage to resolve the problem by doing `sudo chown -R johndoe /usr/local/Library` and `sudo chgrp -R admin /usr/local/Library` – gerrytan Aug 28 '15 at 11:11
  • I screwed up my /usr/local/bin/brew bash script, literally lost the code that belonged in this script, and re-running the install script fixed it. – Devin Rhode Jan 09 '20 at 03:19
  • 2
    You might want to try `brew update-reset` before completely reinstalling. – Boris Verkhovskiy Apr 04 '21 at 19:57

8 Answers8

187

Update 10/11/2020 to reflect the latest brew changes.

Brew already provide a command to uninstall itself (this will remove everything you installed with Homebrew):

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

If you failed to run this command due to permission (like run as second user), run again with sudo

Then you can install again:

/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)"
jcollum
  • 43,623
  • 55
  • 191
  • 321
Ming C
  • 2,476
  • 2
  • 14
  • 8
  • jenkins$ ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)" This script requires the user to be an Administrator. jenkins$ sudo ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)" Password: Don't run this as root! – Sazzad Hissain Khan Mar 07 '17 at 04:20
  • Istalling gave error "This script requires the user to be an Administrator." Although user already is Admin. Please help. – Sazzad Hissain Khan Mar 07 '17 at 04:22
  • This should be the answer! – trusktr May 25 '18 at 21:09
  • Will this also "nuke" the casks that were installed? Does you know if the Homebrew uninstall script will also remove all configs for packages that were installed? If so, is there a way to preserve the settings for the installed packages? – Jason Dec 28 '20 at 22:32
55

Process is to clean up and then reinstall with the following commands:

rm -rf /usr/local/Cellar /usr/local/.git && brew cleanup
ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install )"

Notes:

William Entriken
  • 37,208
  • 23
  • 149
  • 195
  • 3
    This was *almost* enough for me. I also had to run: `brew doctor` And follow its advice, which included running `brew prune` The prune step was the critical one in my case. Apparently brew cleanup didn't remove all the dead symlinks from /usr/local/bin, and doing a `brew install inkscape` got really confused as a result. – burlyearly Aug 27 '14 at 19:16
  • 1
    The install URL has changed to: https://raw.githubusercontent.com/Homebrew/install/master/install – Sebastian N. Oct 16 '14 at 17:59
  • error `This script requires the user to be an Administrator.` although user already is an Admin. Can you please help. – Sazzad Hissain Khan Mar 07 '17 at 04:27
  • It is strange. I have HomeBrew installed and command brew is working, but I don't have the Cellar folder. – Nijat2018 Oct 02 '18 at 02:23
  • 2
    the installation link also now uses bash: `bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)"` – kip2 Apr 08 '20 at 05:00
48

Try running the command brew doctor and let us know what sort of output you get


edit: And to answer the title question, this is from their FAQ :

Homebrew doesn’t write files outside its prefix. So generally you can just rm -rf the folder you installed it in.

So following that up with a clean re-install (following their latest recommended steps) should be your best bet.

kayge
  • 699
  • 7
  • 12
  • Only issue is my Xcode is out of date. But after I ran 'brew install node' the permissions on the node_modules folder was out of whack. I'll add that to my question because maybe I'm looking for the wrong answer. – AndrewKS Jun 14 '12 at 17:18
  • Hmm yea that could potentially cause its own set of issues. Is there any reason not to update Xcode (and Command Line Tools for Xcode)? – kayge Jun 14 '12 at 17:22
  • It's a very small jump - from like 3.2.4 to 3.2.6 and I haven't had the time and bandwidth to download the whole 4 GB file (will do over night tonight) – AndrewKS Jun 14 '12 at 17:27
  • Question about your answer - what about kegs? It looks like if I just rm -rf the kegs there will be a bunch of broken symlinks. Eg. 'which node' returns '/usr/local/bin/node' which is a symlink to the node command in Homebrew's Cellar. – AndrewKS Jun 14 '12 at 17:33
  • Can't say that I've run into that issue personally, but it looks like things can be cleaned up if needed with a combination of `brew doctor` and `brew link/unlink` as needed. Here is some input from the developer on an issue you could potentially run into : https://github.com/mxcl/homebrew/issues/11050 – kayge Jun 14 '12 at 17:39
  • I guess if symlinks are a problem, the best bet would be to uninstall each keg so that the links are removed. I'll mark your answer correct. – AndrewKS Jun 14 '12 at 17:48
  • 1
    Note that "the folder you installed it in" is typically `/usr/local`, and the user may well have installed other things than Homebrew there since it's the standard place to install custom Unix utilities. I install Homebrew to its own `/usr/homebrew` directory specifically so it's easy to remove it and rebuild, but `brew doctor` does warn that a non-standard install place may cause problems. So far, so good. – Nelson Mar 29 '13 at 14:02
14

For Mac OS X Mojave and above

To Uninstall Homebrew, run following command:

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

To Install Homebrew, run following command:

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

And if you run into Permission denied issue, try running this command followed by install command again:

sudo chown -R $(whoami):admin /usr/local/* && sudo chmod -R g+rwx /usr/local/*
Ansari
  • 1,907
  • 2
  • 23
  • 34
  • 2
    according to the install link at https://raw.githubusercontent.com/Homebrew/install/master/install, they now use bash instead of `ruby -e`, so the installation command is now: `bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)"` – kip2 Apr 08 '20 at 04:59
  • Still had to remove /usr/local/Homebrew to fully uninstall. – Justin Geeslin Jul 07 '20 at 23:04
9

The way to reinstall Homebrew is completely remove it and start over. The Homebrew FAQ has a link to a shell script to uninstall homebrew.

If the only thing you've installed in /usr/local is homebrew itself, you can just rm -rf /usr/local/* /usr/local/.git to clear it out. But /usr/local/ is the standard Unix directory for all extra binaries, not just Homebrew, so you may have other things installed there. In that case uninstall_homebrew.sh is a better bet. It is careful to only remove homebrew's files and leave the rest alone.

Jason
  • 9,408
  • 5
  • 36
  • 36
Nelson
  • 27,541
  • 5
  • 35
  • 31
4

For me, I need to do the below steps to re-install the brew from scratch.

sudo rm -rf /usr/local/Cellar/
brew cleanup
sudo rm -rf $(brew --repo)
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
Velu
  • 1,681
  • 1
  • 22
  • 26
2

You can try this method for M1 macbook

After you

1.Uninstall brew

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

2.Install brew again

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

3.You brew install something in image I "brew install sonar-scanner"

then error log show same this

Error: No similarly named formulae found.

enter image description here

4.You should try follow run this.

rm -rf "/usr/local/Homebrew/Library/Taps/homebrew/homebrew-core"

5.When no.4 is done run this

brew tap homebrew/core
  1. try brew install again.
Papon Smc
  • 576
  • 4
  • 11
1

For me, this one worked without the sudo access.

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

For more reference, please follow https://gist.github.com/mxcl/323731

enter image description here

DILIP KOSURI
  • 455
  • 5
  • 10
  • Nah, need to still be an administrator to run this (at the time of this comment) – Jay Nov 08 '18 at 20:09