Skip to content

Instantly share code, notes, and snippets.

@mxcl
Created August 26, 2011 11:25
Show Gist options
  • Save mxcl/1173223 to your computer and use it in GitHub Desktop.
Save mxcl/1173223 to your computer and use it in GitHub Desktop.
Uninstall Homebrew
#!/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!
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
@zmwangx
Copy link

zmwangx commented Oct 19, 2014

This one is insanely dangerous.

  • A $(brew --prefix) with an blank in it (though it shouldn't have happened in the first place) will kill you. So will a somehow broken brew.
  • Why pbcopy and pbpaste are used instead of a command substitution & variable assignment is beyond me — system clipboard could change without notice at any time.
  • There's no git reset --hard so some rm might fail.

In general, when you do rm -rf in a script, you should be absolutely certain that every single thing you run worked as expected. Test $? everywhere (or simply wrap your commands in if ! cmd; then's.

@sergea29
Copy link

Hello I just went through the original commands and after the command :
rmdir -p bin Library share/man/man1 2> /dev/null
I got this:
[Process completed]

I am relatively new to using Terminal and was wondering what to do next.

Thanks

@denisinla
Copy link

@sergea29 It closed your terminal session. Just close and re-open your terminal to continue.

@sergea29
Copy link

Thank you for the help. The original commands were copy/pasted all at once as recommended. So I was surprised it stopped. Before continuing I will input the cd command again. Is there anything else I should do?

@timothyerwin
Copy link

please make a proper uninstall

@bbakersmith
Copy link

This is awful, and doesn't work.

@dmolesUC
Copy link

dmolesUC commented Feb 4, 2015

The test -d /usr/local/.git line should probably be test -d brew --prefix/.git or similar, if it's supposed to handle Homebrew installed somewhere other than /usr/local. (Which seems like the point of the cd line.)

@SteveBenner
Copy link

For anyone seeking a superior method of removing Homebrew, I highly recommend using the uninstaller script I wrote for this purpose. It is robust, safe, unobtrusive, and extremely user-friendly.

@bsl787
Copy link

bsl787 commented Apr 1, 2015

If I use the installer on /usr/local/Cellar/ will it remove all the folders? I have folders such as postgresl, python, and octave. Those I'd like to keep. Will I need to re-install after installing HomeBrew? There are other folders such s gcc, sip, etc. which I presume come with the HomeBrew installation? My reason for removing HomeBrew is that 1) I corrupted the OS on my Yosemite iMac; 2) I had to reinstall the OS; 3) installations of software with HomeBrew still point to the old (corrupt) profile. Thanks from a newbie.

BSL

@bsl787
Copy link

bsl787 commented Apr 1, 2015

Also, do I need to remove the .git directory at /usr/local/ as well? Is .git only associated with HomeBrew?

@renanyoy
Copy link

I dot I remove a broken brew ?

/System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/rubygems/core_ext/kernel_require.rb:55:in require': /usr/local/Library/Homebrew/extend/pathname.rb:259: invalid multibyte escape: /^\037\213/ (SyntaxError) invalid multibyte escape: /^\037\235/ invalid multibyte escape: /^\xFD7zXZ\x00/ from /System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/rubygems/core_ext/kernel_require.rb:55:inrequire'
from /usr/local/Library/Homebrew/global.rb:1:in <top (required)>' from /System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/rubygems/core_ext/kernel_require.rb:55:inrequire'
from /System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/rubygems/core_ext/kernel_require.rb:55:in require' from /usr/local/bin/brew:10:in

'

@self-creative
Copy link

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

so easy!

@luisresearch
Copy link

thanks jacknagel , that worked for me

@xKahlen
Copy link

xKahlen commented Dec 12, 2016

the post from self-creative worked for me. sorry to necro a dead thread but i felt that needed to be said.

@sourcecodemage
Copy link

Thanks self-creative!

@koreycurtis
Copy link

Thanks self-creative! Home brew managed to delete a project with my .git when I tried to commit. It installed poorly and reading through this thread was daunting. Glad I read to the bottom.

@skyler-cs
Copy link

Thanks, @self-creative! You saved my time a lot.

@RahulBhalley
Copy link

RahulBhalley commented Dec 30, 2023

For me this command worked! 🍺
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/uninstall.sh)"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment