Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Uninstall Homebrew
# Just copy and paste the lines below (all at once, it won't work line by line!)
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
Copy link

jvnlwn commented Apr 6, 2014

I used the code in the gist to uninstall Homebrew with the intent of reinstalling Homebrew afterwards. The code seemed to work, but when attempting a reinstall:

ruby -e "$(curl -fsSL"

I got the following:

/Users/joevanleeuwen/.rbenv/shims/ruby: line 21: /usr/local/Cellar/rbenv/0.4.0/libexec/rbenv: No such file or directory

I'm surprised Homebrew would promote this installation process if it is not sufficient, seeing that others have run into issues. I do not know where to go from here.

Copy link

jvnlwn commented Apr 7, 2014

Ah, somehow my $PATH variable was messed up. For some reason was:


I removed /Users/joevanleeuwen/.rbenv/shims: from $PATH and was able to successfully install Homebrew after using the prompted code:

rm -rf /usr/local/Cellar /usr/local/.git && brew cleanup

Copy link

bjarthur commented Apr 17, 2014

i can confirm that rmdir -p bin Library share/man/man1 2> /dev/null is not compatible with set -e and that if those directories are not empty then the script will not finish leaving stuff in .git and Library. how do we go about getting this updated? cc @mxcl

Copy link

ghost commented Apr 24, 2014

I hate dealing with Bash, so I created a rigorous script in Ruby to uninstall Homebrew. It has some nice CLI options, searches a few extra locations for files based on feedback on Stack Overflow, and there is a flexible mechanism for locating Homebrew install locations.

I would love feedback on this; I tested it thorougly, but can't cover all the edge cases for more tricky things like permissions (which is why I advocate the use of sudo to run this). I actually want to contribute to trunk Homebrew at some point but don't have the time yet; I thought I'd at least pitch in my two cents here! Let's start making it easier to uninstall the best Mac package manager guys! The script is here:

Oh, and I thought about changing the permissions of the original directories as part of this, but I'm on the fence. It really seems like something that should be a discrete operation, but I'll probably add the capability at some point.

Copy link

aleczadikian commented Jul 12, 2014

Thanks! I'm switching to Mac Ports because it actually installs stuff rather than putting it into a separate directory and refusing to let me use sudo to link anything.

Copy link

nickb-minted commented Jul 16, 2014

looks like homebrew allows you to uninstall it with this command

 rm -rf /usr/local/Cellar /usr/local/.git && brew cleanup

Copy link

dylanfoster commented Jul 18, 2014

#!/usr/bin/env bash

set -e

notice() { echo -e "\033[1;32m=> $1\033[0m"; }


read -p "Deleting all Homebrew directories. Are you sure (y/n)?" yn
case $yn in
  [Yy]* )
    for dir in "${dirs[@]}"; do
      notice "deleting ${dir}"
      sudo rm -r $dir
      [Nn]* ) return;;
* ) "Please enter yest or no";;

Copy link

Removed-5an commented Jul 26, 2014

Is the comment proposed by dylan947 a legit way of removing homebrew? I'm holding off installing till I know there is a clean way of uninstalling.

Copy link

ghost commented Aug 3, 2014

Will original script above still work and remove Homebrew completely? I am new to this but I need to know if above original uninstall instruction works.

Background if needed -
I tried installing Homebrew few days ago but terminal kept giving me different warning messages, something about some python file and some other stuff I don't know about. An instructor, in a class I am taking, uninstalled some files that were getting in a way and it we got it to install . Unfortunatly it still wouldn't work, due to what I think is a perl file. We gave up after that and I am using some gui solution. Homebrew still doesn't work and I want to get rid of it. Please help.

Copy link

Dygear commented Aug 6, 2014

After running the commands here, I'm still being told that homebrew is already installed on my system, when I try to do a reinstall.

MacBook-Pro:~ Dygear$ ruby -e "$(curl -fsSL"
It appears Homebrew is already installed. If your intent is to reinstall you
should do the following before running this installer again:
    rm -rf /usr/local/Cellar /usr/local/.git && brew cleanup
MacBook-Pro:~ Dygear$ 

Doing what it suggests results in this:

MacBook-Pro:~ Dygear$ rm -rf /usr/local/Cellar /usr/local/.git && brew cleanup
-bash: brew: command not found

Any ideas?

Copy link

Codeguyross commented Aug 28, 2014

running cd brew --prefix tells me:
line 13: cd: /Library/Frameworks/Python.framework/Versions/2.7/bin/../Library: No such file or directory
/Library/Frameworks/Python.framework/Versions/2.7/bin/brew: line 23: /brew.rb: No such file or directory
/Library/Frameworks/Python.framework/Versions/2.7/bin/brew: line 23: exec: /brew.rb: cannot execute: No such file or directory

Anything i run with brew tells me the same error. If i trye to reinstall brew using:
ruby -e "$(curl -fsSL"

it tells me to run:
rm -rf /usr/local/Cellar /usr/local/.git && brew cleanup

which also tells me the same thing i get told when i run cd brew --prefix

Any ideas?

Copy link

patrickburdine commented Sep 23, 2014

I am having the same problem as Dygear. Any ideas? I tried running the script and got the following:

$ /bin/sh
brew update first!

but brew update gives me:

$ brew update
-bash: brew: command not found

I tried looking for a /usr/local/Cellar but it doesn't exist.

Copy link

fxi commented Sep 23, 2014

@somnicide it's a message from the original gist/script above: there is no .git directory.

test -d /usr/local/.git || abort "brew update first!"

If you don't have /usr/local/Cellar, your hombrew installation could be already removed, except if you installed homebrew elsewhere..

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.

Copy link

sergea29 commented Oct 26, 2014

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.


Copy link

denisinla commented Oct 29, 2014

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

Copy link

sergea29 commented Oct 29, 2014

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?

Copy link

timothyerwin commented Nov 11, 2014

please make a proper uninstall

Copy link

bbakersmith commented Dec 19, 2014

This is awful, and doesn't work.

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

Copy link

SteveBenner commented Feb 9, 2015

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.

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.


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?

Copy link

renanyoy commented Apr 29, 2015

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


Copy link

self-creative commented Dec 25, 2015

Copy link

luisresearch commented Jan 7, 2016

thanks jacknagel , that worked for me

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.

Copy link

majorgear commented Aug 17, 2017

Thanks self-creative!

Copy link

koreycurtis commented Feb 21, 2018

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.

Copy link

skyler-cs commented Sep 1, 2018

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

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