Embed URL


SSH clone URL

You can clone with HTTPS or SSH.

Download Gist

Uninstall Homebrew

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
# 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

May want to make a note that the user needs write permission on HOMEBREW_PREFIX to execute some of these commands. If they installed it correctly it won't be an issue, but cf. mxcl/homebrew#7578.

It would be a good idea to use a temporary file instead of pbcopy, since the user may be copying and pasting these commands one by one.

Warning: If you are using this to remove a somehow broken Homebrew installation you should make ABSOLUTELY sure that the first cd statement succeeds.

In my case the cd failed, the "git puts files on the clipboard" failed and the rest of the script ran it's deletion magic (including whatever was on the clipboard) in my home dir where my shell session started.

Nothing critical lost, but I am still wiping sweat from my brow. Pay attention to the stuff in caps above. :-)

Could probably stick && after each command, or set -e at the top of the script.


I added set -e. I have resisted rewriting in Ruby as I want people to be able to understand what it does without reading a massive script with error handling. Probably time to bite the bullet though.

@mxcl: Your responsiveness never fails to impress me and is hugely appreciated. :-)

utterly useless for a broken brew installation, grr! Which os x lion upgrade seems to make of them


@inspire22 could you describe your problems so we can fix them?

Sorry for being grumpy :) For some reason the calls to brew were then suddenly closing my terminal, so it was difficult to see the exact error. (perhaps it was "set -e" that was causing this?)

This had been my error, which is why I was trying to reinstall.
/usr/local/Library/Homebrew/utils.rb:2:in require': no such file to load -- exceptions (LoadError)
from /usr/local/Library/Homebrew/utils.rb:2
from /usr/local/Library/Homebrew/global.rb:4:in
from /usr/local/Library/Homebrew/global.rb:4
from /usr/local/bin/brew:9:in `require'
from /usr/local/bin/brew:9

I ended up removing the Library and .git folders and reinstalling seems to be working now, thanks.

Didn't remove /usr/local/.git


@projectvictory Line 15 does that. I'm guessing your .git was owned by root or something.

I have a similar issue. I installed homebrew with an admin user whose umask is 077 (which I have since understood is a bad idea). I now wanted to uninstall and start from a clean slate -- but it fails with

fatal: Not a git repository (or any of the parent directories): .git

I havd checked, and /usr/local does indeed not have a .git subfolder.

Is my best bet to simply remove /usr/local/Library? (I don't believe I ever got to install anything with brew...)


@ukrutt it'll work if you do brew update first. Or maybe if you just do git init in /usr/local. Failing that, like the FAQ says, you can prolly just delete the whole of /usr/local.

I don't know if you've changed this recently or what, but I just installed brew and /usr/local is not a git repository. So git ls-files fails.

@sbwoodside Had you run brew update? brew update sets up the git repository.

I just tried running it and the script leaves the file as well as a /usr/local/bin/brew file. Hopefully nothing is broken.


This needs to be a proper ruby script.

Just for the record, I ran into a problem running your command to install brew on my MacBook Air (v. 10.6.8):
/usr/bin/ruby -e "$(curl -fsSL"
This uses the default version of Ruby (1.8.7, I believe). When I used this default version of Ruby to install homebrew, I got this error:
-bash: /usr/local/bin/brew: /usr/bin/ruby^M: bad interpreter: No such file or directory
After doing some research online, the problem appeared to be caused by this old Ruby interpreter. The problem was that I couldn't even run your script because it depends on the brew executable which, itself, was broken.
To fix the problem, I renamed brew to brew.old and used this command to strip out the CRLF:
tr -d '\r' < brew.old > brew
Once I did that, I could uninstall brew.
Since I use RVM, I made Ruby 1.9.3-p0 (which I had installed) the default interpreter and re-ran your installation command without the "/usr/bin" prefix. This time brew installed correctly. I don't know why homebrew wouldn't install with Ruby 1.8.7 on my machine but hopefully this information will help someone else.


@robertf57 The \r was the problem, somewhere something inserte the \r, just stripping that would have fixed it. I cannot say why it was inserted. CURL wouldn't do it.

rm -rf /usr/local/.git

There's a typo:
The line: "rm -rf ~/Library/Caches/Homebrew" is there twice. I think you probably meant to have it once, but also have "rm -rf /Library/Caches/Homebrew". was left behind.

@iislucas I think you are correct. I wondered about that too. I tried to do a clean reinstall and then I got an error about not being able to write into /Library/Caches/Homebrew/ Sure enough it was still there... owned by system.

Quick question . . . in which directory should I be before running these commands - /usr/local?

mxcl commented

@lolaji the first line changes the directory, for reference, see the first line of the script. IE, the line of the script that changes the directory to the directory the script needs to be in before it executes any commands.

mxcl commented

Any files that are left behind either couldn't be deleted due to permissions issues or weren't in the git repo for Homebrew, and that would only be the case if something is fucked up.

What do do if there is no git repository in /usr/local? (I installed brew on a previous machine last summer; .git seems to have been lost in the move or was never there to begin with.) I've got quite a lot in /usr/local from other software, but my brew installation is broken (can't write to Cellar to install things).

mxcl commented

@naylor127 If you can't brew update then this is pretty equivalent:

cd /usr/local
rm -rf Library Cellar
brew prune
rm bin/brew

Thanks for the help! I did as suggested (eventually); when I got to brew prune (after removing Library and Cellar) I had the following error:

/usr/local/bin/brew:9:in `require': no such file to load -- global (LoadError)

Is this to be expected and can I safely remove bin/brew now?

BTW I had only installed one program using brew: that was Emacs. So I guess I need to go into /usr/local/bin and remove any links pointing to Emacs files in Cellar there.

hmm tried installing homebrew for some reason my Xcode is not installed with proper path tried uninstalling homebrew first to check my Xcode installation but i get errors running your script that i should install git first and ends with process completed my question of course is what is the best way to proceed from here ?

looked at comment above and installed git and updated successfully

Doesn't Homebrew also make ownership changes to some of the directories? Optimally a full uninstall would undo those also, right?

I second what @studgeek said. I would think a full uninstall would leave things as it found them and that includes directory permissions and groups.

iromu commented

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

If Homebrew is installed in other location, this will stop the script

This fails to remove /usr/local/Library/Taps, i.e after installing homebrew-dupes.

Should it remove the .gitignore too! :-)

This script doesn't work and I don't have time to fiddle with it. Homebrew is easy to install - it should be easy to uninstall as well.

mxcl commented

Tempted to delete this script and replace the instructions with rm -rf /usr/local again.

mxcl commented

But I don't have the time to fiddle with it.

a little tweak to make this work like a charm

line 17 should read git checkout -f master

tlc commented

The FAQ says that this gist uninstalls ONLY the homebrew stuff.
The FAQ says that Cellar is the place to install non-homebrew stuff.
This gist removes Cellar.

I found a fix for the problem when you get an error like this:
/usr/local/Library/Homebrew/global.rb:6:in `require': no such file to load -- set (LoadError)
The file being loaded may differ.

If you look in /usr/local/bin/brew you see:
#!/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/bin/ruby -W0

This is forcing system ruby to be used by the script. I changed that first line, and it has to be the first line in the script to:
#!#!/Users/colmac/.rvm/rubies/ruby-1.8.7-p370/bin/ruby -W0
you will use your version of ruby. Find that by
Prompt> which ruby

Then change the first lines in the brew script to
#!/Users/colmac/.rvm/rubies/ruby-1.8.7-p370/bin/ruby -W0
#####!/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/bin/ruby -W0

notice I moved my ruby to the top and added #!, that is important
and I added a few #### to the original ruby path, just to keep the original in the script.

Every thing worked fine after that

i have a typo
This is forcing system ruby to be used by the script. I changed that first line, and it has to be the first line in the script to:
#!#!/Users/colmac/.rvm/rubies/ruby-1.8.7-p370/bin/ruby -W0

should have been:
This is forcing system ruby to be used by the script. I changed that first line, and it has to be the first line in the script to:
#!/Users/colmac/.rvm/rubies/ruby-1.8.7-p370/bin/ruby -W0


wow, very sorry. I posted the above on the wrong gist. I meant to post to issues/12522
you can delete the posts if you need.

I've forked this at this is updated as I needed 'Sudo' and couldn't uninstall

Didn't remove a bunch of files:


I'd really like to see a script that would simply link/unlink homebrew from /usr/local/. So I'd like to be able to unwind it, and then reinstate it. I guess if I used a different prefix, this wouldn't have been necessary… but I didn't.

Note that this will not necessarily work in tmux due to the use of pbcopy.

set -e
does not work well with
rmdir -p bin Library share/man/man1 2> /dev/null

the latter command tries to remove those directories if they are nonempty. but it fails (silently) with a nonzero exit status if they aren't. so if i have non-brew stuff installed in /usr/local/bin (a very common scenario) then the script terminates at that point leaving me with /usr/local/.git, etc.

For what it's worth, .git and a few other files/folders aren't removed. I ran the script, read through the comments above and cleaned up whatever else people have found isn't removed and then...

sudo find / -name "*brew*"

...showed me the rest.

Just read through the list and remove only the Homebrew ones. Careful with the theme that's called Homebrew, you probably want to keep that.

I'm uninstalling homebrew, but my terminal seems to have 'stopped' at

rm -rf /Library/Caches/Homebrew

Here is my terminal output

darcydamato@darcydamato ~ $ cd `brew --prefix` 
darcydamato@darcydamato /usr/local $ git checkout master
Already on 'master'
darcydamato@darcydamato /usr/local $ git ls-files -z | pbcopy
darcydamato@darcydamato /usr/local $ rm -rf Cellar
darcydamato@darcydamato /usr/local $ bin/brew prune
Pruned 36 symbolic links and 2 directories from /usr/local
darcydamato@darcydamato /usr/local $ pbpaste | xargs -0 rm
darcydamato@darcydamato /usr/local $ rm -r Library/Homebrew Library/Aliases Library/Formula Library/Contributions 
darcydamato@darcydamato /usr/local $ test -d Library/LinkedKegs && rm -r Library/LinkedKegs
darcydamato@darcydamato /usr/local $ rmdir -p bin Library share/man/man1 2> /dev/null
darcydamato@darcydamato /usr/local $ rm -rf .git
darcydamato@darcydamato /usr/local $ rm -rf ~/Library/Caches/Homebrew
darcydamato@darcydamato /usr/local $ rm -rf ~/Library/Logs/Homebrew
darcydamato@darcydamato /usr/local $ rm -rf /Library/Caches/Homebrew

Sorry, when I say stopped, I mean it's as if it's paused or something.

I figured it out. I apologize for wasting space here. hehe ^^; Having a sinus infection really makes me overlook the obvious things. I just assumed it was still working since it didn't go to the next line and just say
darcydamato@darcydamato /usr/local $
When I see that, I know it's done, but I just closed the window to see if I would get an alert message saying something like 'closing the window will terminate the running processes', but I didn't get that, so apparently it finished. I just got confused because I was waiting for that.

After using this script I then reinstalled homebrew, but had problems with Taps. When trying to add them they showed as already tapped but the forumla were missing. I ended up deleting /usr/local/Library/Taps/various-taps-directory then tapping them - worked fine.

@coldclimate thanks for the tip.

Can we also add this to the gist: rm -rf /usr/local/Library/Taps

@mxcl Can't you use absolute paths? I ran it and it blew away my project's .git directory.

I think this would be a lot more useful as a step by step guide on how to uninstall Homebrew rather than a script, because uninstalling Homebrew isn't something I'm likely to do very often, and when I do, I want to know exactly what I'm doing and why.

Thanks, Sire, in advance for the helpful snippet of code and the subsequent posters for their willingness to improve.

I had Homebrew installed and then uninstalled over a year ago. My deinstallation was incomplete, as I now found out: as /usr/local/bin/brew was still in place and its presence made some nifty configure script think Homebrew was still installed.

Your snippet helped to make sure that all other fragments mentioned are now also removed. Thanks again!

Argh… Since I used this script my MacBook Pro won't boot properly into OS X any more. I am a bit at a loss as to what to do now.

Complete crap the program doesn't have an uninstall process that works. Throwing out hacked up scripts does nothing but break people's systems.

This script does NOT remove homebrew correctly. Do not use it under any circumstances until it is updated.

The uninstall is not complete, causes serious issues under certain unknown circumstances and may require a reinstall (archive and install not format and install) of OSX.

You could consider adding lines like these to the script (or just one regex) because it is likely that a user reinstalling brew might have some of these unbrewed files.

rm -f /usr/local/lib/*.dylib
rm -f /usr/local/lib/*.la
rm -f /usr/local/lib/pkgconfig/*.pc
rm -f /usr/local/lib/*.a

It should be easier than this to uninstall Homebrew.

I uninstalled the homebrew located in /usr/local
Still I fount the .git file so as per above comments, I have remove entier /urs/local folder !!

Still php was not running, so den I edited the .bash_profile and remove the /local from the path.

and then when I tried to run php, it was not running !! writing mysql on command line was not running !!
My whole mysql was gone, no database nothing was happening.

My system has phpmyadmin, but no mysql installed !!
getting mad !!

Any help appreciated to setup my local environment again with the symlinks !!
Please help !!

Here's what I'm getting.

SALAR:~ salarkhan$ function abort {
echo "$1"
exit 1
SALAR:~ salarkhan$

SALAR:~ salarkhan$ set -e
SALAR:~ salarkhan$

SALAR:~ salarkhan$ /usr/bin/which -s git || abort "brew install git first!"
-bash: !": event not found
SALAR:~ salarkhan$ test -d /usr/local/.git || abort "brew update first!"
-bash: !": event not found
SALAR:~ salarkhan$

SALAR:~ salarkhan$ cd brew --prefix
SALAR:local salarkhan$ git checkout master
-bash: git: command not found

AKA it fails on everything. I ran this maybe 10 minutes after installation, which no changes to any files, btw.

I think this script is a mess. There are many deletion operations in it and no checks, if operations done before went right. There really should be --- a well tested --- with unit tests --- an uninstall option by brew itself.

I'm trying to uninstall homebrew from my usr/local/bin but it's failing with this error message: Reason: ErrorMissingBundle

Just open vim and input the script

So go to terminal:
cd /usr/local
ls (you should see brew)

copy and paste the above script
shift + :
sudo chmod +x (to make it executable)
then in the terminal type - ./

Goodbye HomeBrew --- worked like a charm..

I managed to get rid of homebrew in less time than it takes to brew a full pot of coffee with this script. Just copy-paste into TextMate and save. TextMate was even nice enough to +x it for me!

This script leaves this directories with content:


I recommend to check all symlinks and unused files manually.

This script did not work to remove homebrew for me. I ran it overnight and it just doesn't seem to execute. I don't get any error messages. This is what happened:

I copied and pasted the script into the command line (while in the /usr/local directory), and hit enter.
Almost immediately I got a message that said [process completed]
However, it never returned me to the command line prompt. I left it overnight this way, and it was still the same this morning.
I quit terminal to get back to the command line and did an ls -l and all the files and directories are still there:

drwxr-xr-x 21 root wheel 714 Dec 9 2012 Cellar
drwxr-xr-x 9 root wheel 306 Dec 9 2012 Library
-rwxrwxrwx 1 leah admin 789 Sep 13 2012
drwxr-xr-x 72 root wheel 2448 Nov 2 17:14 bin
drwxr-xr-x 6 root wheel 204 Dec 9 2012 etc
drwxr-xr-x 15 root wheel 510 Dec 9 2012 include
drwxr-xr-x 28 root wheel 952 Dec 9 2012 lib
drwxr-xr-x 21 root wheel 714 Dec 9 2012 opt
drwxr-xr-x 14 root wheel 476 Dec 9 2012 share
drwxr-xr-x 5 root wheel 170 Dec 9 2012 var

(the user leah on the readme file is me)

Since this didn't work I decided I'd just remove the files and directories by hand. I tried first to delete the readme file by using rm
This returned a permission error, which I don't understand because I set the permission to 777 on that document.

After that I decided to try removing a whole directory. I tried rm -rf Cellar and got a string of permissions errors (one for every subdirectory):
rm: Cellar/apple-gcc42: Permission denied
rm: Cellar/autoconf: Permission denied
rm: Cellar/automake: Permission denied
rm: Cellar/gdbm: Permission denied
rm: Cellar/git: Permission denied
rm: Cellar/json-c: Permission denied
rm: Cellar/libevent14: Permission denied
rm: Cellar/openssl: Permission denied
rm: Cellar/pkg-config: Permission denied
rm: Cellar/ps_to_http: Permission denied
rm: Cellar/pubsub: Permission denied
rm: Cellar/pubsubclient: Permission denied
rm: Cellar/python: Permission denied
rm: Cellar/readline: Permission denied
rm: Cellar/redis: Permission denied
rm: Cellar/simplehttp: Permission denied
rm: Cellar/simplequeue: Permission denied
rm: Cellar/sqlite: Permission denied
rm: Cellar/wget: Permission denied
rm: Cellar: Permission denied

So clearly I'm having some type of permissions situation.

I'd really like to completely remove Homebrew, and then do a fresh installation of if. Help would be greatly appreciated.

This missed the .git directory by they way. So when I tried to reinstall homebrew using:

ruby -e "$(curl -fsSL"

It complained:
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

Which didn't work since 'brew' is no longer installed. However, running the first rm command worked fine.

The lack of a clean ability to restore the state of the system to its pre-brew state seems to be a serious integrity issue. The current script can not even restore the system to a state that you can reinstall brew.

Should the spaces be properly escaped with a \ ?

Note: I managed to have an install of brew that fails

/usr/local/bin/brew:34:in `<': comparison of String with Float failed (ArgumentError)
from /usr/local/bin/brew:34

and thus this script doesn't work.

I installed brew in the default directory. However, it didn't work properly, probably because I have other things installed in this folder. This is actually what the command "brew doctor" tells me might be wrong. Therefore I decided to remove homebrew and install it in a different directory. It seems however that I am unable to uninstall the software, I tried to run the script as described above (I messed up first by copying it into a bash shell, I hadn't noticed it was sh). However now that I tried to run it in sh as a script I get the following error, and I have no idea how to fix this:

sh-3.2$ sh uninstall_hb 
Already on 'master'
dyld: Symbol not found: _xmlBufContent
  Referenced from: /usr/lib/libxslt.1.dylib
  Expected in: /usr/local/lib/libxml2.2.dylib
 in /usr/lib/libxslt.1.dylib
uninstall_hb: line 17: 67888 Broken pipe: 13         git ls-files -z
     67889 Trace/BPT trap: 5       | pbcopy

If I have to remove folders one by one by hand, that would be fine to. However, I'm still quite new to the UNIX/terminal environment, so I don't want to mess anything up.

Any help would be appreciated,

Worked fine! Thanks

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.

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

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

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.

looks like homebrew allows you to uninstall it with this command

 rm -rf /usr/local/Cellar /usr/local/.git && brew cleanup
#!/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";;
5an1ty commented

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.

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?

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?

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.

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

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.

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.


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

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?

please make a proper uninstall

This is awful, and doesn't work.

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

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.