Uninstalling and re-installing Homebrew on OSX

Author

Dheepak Krishnamurthy

Published

August 28, 2015

Keywords

how to install homebrew on osx, how to remove homebrew on osx

Gist

#!/bin/sh
# Just copy and paste the lines below (all at once, it won't work line by line!)
# MAKE SURE YOU ARE HAPPY WITH WHAT IT DOES FIRST! THERE IS NO WARRANTY!

brew list > ~/brew_list.txt

function abort {
  echo "$1"
  exit 1
}

set -e

/usr/bin/which -s git || abort "brew install git first!"
test -d /usr/local/.git || abort "brew update first!"

cd $(brew --prefix)
git checkout master
git ls-files -z | pbcopy
rm -rf Cellar
bin/brew prune
pbpaste | xargs -0 rm
rm -r Library/Homebrew Library/Aliases Library/Formula Library/Contributions
test -d Library/LinkedKegs && rm -r Library/LinkedKegs
rmdir -p bin Library share/man/man1 2> /dev/null
rm -rf .git
rm -rf ~/Library/Caches/Homebrew
rm -rf ~/Library/Logs/Homebrew
rm -rf /Library/Caches/Homebrew

Set permission on Homebrew folder

sudo chown -R $USER /Library/Caches/Homebrew/

Reuse

Citation

BibTeX citation:
@online{krishnamurthy2015,
  author = {Krishnamurthy, Dheepak},
  title = {Uninstalling and Re-Installing {Homebrew} on {OSX}},
  date = {2015-08-28},
  url = {https://kdheepak.com/blog/uninstalling-and-reinstalling-homebrew-on-osx/},
  langid = {en}
}
For attribution, please cite this work as:
D. Krishnamurthy, “Uninstalling and re-installing Homebrew on OSX,” Aug. 28, 2015. https://kdheepak.com/blog/uninstalling-and-reinstalling-homebrew-on-osx/.