What is the best/safest way to reinstall Homebrew?
Asked Answered
S

8

138

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!
Seka answered 14/6, 2012 at 17:7 Comment(3)
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/LibrarySalter
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.Upend
You might want to try brew update-reset before completely reinstalling.Otes
G
200

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)"
Greatest answered 16/4, 2016 at 5:2 Comment(4)
jenkins$ ruby -e "$(curl -fsSL raw.githubusercontent.com/Homebrew/install/master/install)" This script requires the user to be an Administrator. jenkins$ sudo ruby -e "$(curl -fsSL raw.githubusercontent.com/Homebrew/install/master/install)" Password: Don't run this as root!Lie
Istalling gave error "This script requires the user to be an Administrator." Although user already is Admin. Please help.Lie
This should be the answer!Conway
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?Uis
D
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:

Diffident answered 16/3, 2014 at 16:54 Comment(5)
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.Meghan
The install URL has changed to: raw.githubusercontent.com/Homebrew/install/master/installStony
error This script requires the user to be an Administrator. although user already is an Admin. Can you please help.Lie
It is strange. I have HomeBrew installed and command brew is working, but I don't have the Cellar folder.Mcintosh
the installation link also now uses bash: bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)"Martamartaban
A
49

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.

Adversative answered 14/6, 2012 at 17:15 Comment(7)
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.Seka
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)?Adversative
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)Seka
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.Seka
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 : github.com/mxcl/homebrew/issues/11050Adversative
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.Seka
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.Fraught
S
15

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/*
Simmons answered 7/7, 2019 at 11:51 Comment(2)
according to the install link at 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)"Martamartaban
Still had to remove /usr/local/Homebrew to fully uninstall.Einstein
F
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.

Fraught answered 29/3, 2013 at 15:17 Comment(2)
I recommend reading the Homebrew FAQ linked above, has well written documentation on how to best best & safely reinstall.Magnuson
Link to FAQ page is broken, this should have more chances of survival: docs.brew.sh/FAQHolily
W
5

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)"
Whisker answered 25/3, 2021 at 17:38 Comment(0)
T
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.
Tribune answered 10/11, 2022 at 10:59 Comment(0)
M
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

Mosley answered 9/7, 2017 at 10:26 Comment(1)
Nah, need to still be an administrator to run this (at the time of this comment)Nape

© 2022 - 2024 — McMap. All rights reserved.