AndrewKS
AndrewKS

Reputation: 3877

What is the best/safest way to reinstall Homebrew?

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!

Upvotes: 145

Views: 271423

Answers (8)

Ansari
Ansari

Reputation: 1935

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/*

Upvotes: 16

Papon Smc
Papon Smc

Reputation: 688

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.

Upvotes: 2

Nelson
Nelson

Reputation: 29786

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.

Upvotes: 9

Velu
Velu

Reputation: 1911

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)"

Upvotes: 5

Ming C
Ming C

Reputation: 2746

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)"

Upvotes: 214

DILIP KOSURI
DILIP KOSURI

Reputation: 465

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

Upvotes: 1

William Entriken
William Entriken

Reputation: 39313

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:

Upvotes: 55

kayge
kayge

Reputation: 719

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.

Upvotes: 50

Related Questions