Ask Different is a question and answer site for power users of Apple hardware and software. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

How can I cleanly remove Homebrew. I might have a faulty older installation, and I'd like to have a fresh start.

share|improve this question
See also… which has answers that describe a "now canonical" way to remove homebrew – rogerdpack Mar 11 at 18:41
@rogerdpack Comments may get deleted anytime, can you please post an answer describing the new method? – patrix Mar 11 at 21:15

Try this in your Terminal:

cd `brew --prefix`
rm -rf Cellar
brew prune
rm `git ls-files`
rm -r Library/Homebrew Library/Aliases Library/Formula Library/Contributions
rm -rf .git
rm -rf ~/Library/Caches/Homebrew

More info about this topic can be found in the Homebrew FAQ.

share|improve this answer
I would check that the cd `brew --prefix` goes to a folder that you don't have normal git files checked in since an old / malfunctioning setup might fail and the deletion of git ls-files could delete something other than the remains of your brew. – bmike Feb 20 '13 at 13:57
I updated the link in my answer. Basically, every file you've added there manually well be left intact. – Michiel Feb 20 '13 at 14:01
Excellent - calling that out explicitly is a great addition. +2 if I could. – bmike Feb 20 '13 at 14:07
I did read the documentation, I just thought that might be an useful question to ask for future reference. I do have problems with the instructions though, which I posted as a separate question:… – ipavlic Feb 20 '13 at 21:04
Note that the link to the Homebrew FAQ should be updated from… to… (I can't edit or add comments). – cloudnthings Mar 16 at 23:01

Here is a much better solution for removing Homebrew:

#!/usr/bin/env ruby
# Locates and removes Homebrew installation
# Author: Stephen Benner
require 'optparse'
require 'fileutils'
require 'open3'

$stdout.sync = true

# Default options
options = {
  :quiet     => false,
  :verbose   => true,
  :dry_run   => false,
  :force     => false,
  :find_path => false

optparser = do |opts|
  opts.on('-q', '--quiet', 'Quiet mode - suppress output.') do |setting|
    options[:quiet]   = setting
    options[:verbose] = false
  opts.on('-v', '--verbose', 'Verbose mode - print all operations.') { |setting| options[:verbose] = setting }
  opts.on('-d', '--dry', 'Dry run - print results, but perform no actual operations.') do |setting|
    options[:dry_run] = setting
  opts.on('-f', '--force', 'Forces removal of files, bypassing prompt. USE WITH CAUTION.') do |setting|
    options[:force] = setting
  opts.on('-p', '--find-path', 'Output homebrew location if found, then exit.') do |setting|
    options[:find_path] = setting
    options[:quiet]     = true
  opts.on('-h', '--help', '--usage', 'Display usage info and quit.') { puts opts; exit }
$quiet = options[:quiet] # provides access to option value within methods

# Files installed into the Homebrew repository
# Files that Homebrew installs into other system locations
$files = []

# This function runs given command in a sub-shell, expecting the output to be the
# path of a Homebrew installation. If given a block, it passes the shell output to
# the block for processing, using the return value of the block as the new path.
# Known Homebrew files are then scanned for and added to the file list. Then the
# directory is tested for a Homebrew installation, and the git index is added if
# a valid repo is found. The function won't run once a Homebrew installation is
# found, but it will accumulate untracked Homebrew files each invocation.
# @param  [String] cmd       a shell command to run
# @param  [String] error_msg message to print if command fails
def locate_brew_path(cmd, error_msg = 'check homebrew installation and PATH.')
  return if $brew_location # stop testing if we find a valid Homebrew installation
  puts "Searching for homewbrew installation using '#{cmd}'..." unless $quiet

  # Run given shell command along with any code passed-in via block
  path = `#{cmd}`.chomp
  path = yield(path) if block_given? # pass command output to your own fancy code block

    Dir.chdir(path) do
      # Search for known Homebrew files and folders, regardless of git presence
      $files += { |file| File.exist? file }.map {|file| File.expand_path file }
      $files += Dir.glob('**/{man,bin}/**/brew*')
      # Test for Homebrew git repository (use popen3 so we can suppress git error output)
      repo_name = Open3.popen3('git remote -v') do |stdin, stdout, stderr|
      if repo_name =~ /homebrew.git|Homebrew/
        $brew_location = path
  rescue StandardError # on normal errors, continue program

# Attempt to locate homebrew installation using a command and optional code block
# for processing the command results. Locating a valid path halts searching.
locate_brew_path 'brew --prefix'
locate_brew_path('which brew') { |output| File.expand_path('../..', output) }
locate_brew_path 'brew --prefix' do |output|
  output = output.split($/).first
  File.expand_path('../..', output)

# Found Homebrew installation
if $brew_location
  puts "Homebrew found at: #{$brew_location}" unless options[:quiet]
  if options[:find_path]
    puts $brew_location
  # Collect files indexed by git
    Dir.chdir($brew_location) do
      # Update file list (use popen3 so we can suppress git error output)
      Open3.popen3('git checkout master') { |stdin, stdout, stderr| stderr.close }
      $files += `git ls-files` {|file| File.expand_path file }
  rescue StandardError => e
    puts e # Report any errors, but continue the script and collect any last files

# Collect any files Homebrew may have installed throughout our system
$files += { |file| File.exist? file }

abort 'Failed to locate any homebrew files!' if $files.empty?

unless options[:force]
  print "Delete #{$files.count} files? "
  abort unless gets.rstrip =~ /y|yes/i

rm =
  if options[:dry_run]
    lambda { |entry| puts "deleting #{entry}" unless options[:quiet] }
    lambda { |entry| FileUtils.rm_rf(entry, :verbose => options[:verbose]) }

puts 'Deleting files...' unless options[:quiet]
share|improve this answer
Welcome to Ask Different! While the link you provided may answer the question, it is better to include the answer here and provide the link for reference. Link-only answers can become invalid if the linked page changes. I've edited your question to include what I believe was the solution that you were referring to, however if it wasn't please quote the relevant section. Also, could you expand on why your solution is better? – grgarside Apr 24 '14 at 14:26
It's more than a few lines so I thought including the code would be cumbersome, but I'm happy to do so in the future. It's better because there are files and directories not caught by the posted answer which my script will remove. It is provides utility for the user via CLI options, searches more exhaustively for brew locations, and is coded so as to make it easy to modify in case you want to improve the script. – Steve Benner Apr 25 '14 at 21:45

protected by bmike Mar 17 at 1:07

Thank you for your interest in this question. Because it has attracted low-quality or spam answers that had to be removed, posting an answer now requires 10 reputation on this site.

Would you like to answer one of these unanswered questions instead?

Not the answer you're looking for? Browse other questions tagged or ask your own question.