1

I removed ALL content from /usr/local/bin folder (including 'brew'). Homebrew isn't working anymore and I seem to be stuck in a limbo. When I try to install it says:

It appears Homebrew is already installed. If your intent is to reinstall you should do the following before running this installer again: ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/uninstall)"

When I run the given uninstall command it says:

Failed to locate Homebrew!

Background

The problem arose when I attempted to remove node.js by following this guide: https://stackoverflow.com/a/11178106/1736012

To completely uninstall node + npm is to do the following:

  1. go to /usr/local/lib and delete any node and node_modules
  2. go to /usr/local/include and delete any node and node_modules directory
  3. if you installed with brew install node, then run brew uninstall node in your terminal
  4. check your Home directory for any local or lib or include folders, and delete any node or node_modules from there
  5. go to /usr/local/bin and delete any node executable

Especially 5 was bad! That's what led me to remove everything under /usr/local/bin. So brew doctor won't work (brew isn't recognized anymore). Brew worked fine before this.

What I tried

This does not work either as brew is missing:

rm -rf /usr/local/Cellar /usr/local/.git && brew cleanup
ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install )"

I tried various scripts like this one for example: https://apple.stackexchange.com/a/85481. And this: https://gist.github.com/SteveBenner/11254428. None of them is working (both assumes that brew command is there)...

What can I do to re install Homebrew so that it works as before??

Community
  • 1
  • 1
olefrank
  • 4,204
  • 7
  • 45
  • 75
  • well `rm -rf /usr/local/.git` was a horrible decision... Now you also lost an easy way to track files that belong to homebrew. – cel Oct 02 '15 at 05:43
  • I'm new to MacOS so I didn't know what I was doing...! – olefrank Oct 02 '15 at 06:42
  • I think I would open a ticket at `github` and ask the devs how to proceed. The problem is that you now lost track of which files actually belong to homebrew, so probably there is no clean uninstallation routine anymore and files need to be removed manually. – cel Oct 02 '15 at 06:50
  • The linked files are/were actually in `Cellar` and the git dir would have been easy to restore. Probably you just need to more fully clean out /usr/local and reinstall as above with the snippet. – Ian Oct 02 '15 at 07:29
  • @IanLancaster, how would you restore the `.git` folder? With the git folder it would be very easy to adapt the official uninstallation routine. – cel Oct 02 '15 at 08:20
  • `git clone https://github.com/Homebrew/homebrew.git` and copy the resulting `homebrew/.git` directory to `/usr/local/.git`. You can also copy over the brew command. But this is manually restoring brew not removing it and starting from scratch. – Ian Oct 02 '15 at 08:31
  • @IanLancaster, right - stupid of me. The cleaner way is to do a `git init`, add the git repo and then simply fetch upstream commits. I think this will make it relatively easy to perform a clean reinstall. I'll probably answer by tonight if nobody else wants to do it. – cel Oct 02 '15 at 08:54
  • I already tried to copy the 'brew' file back to /usr/local/bin but it did not solve the problem. brew is not recognized – olefrank Oct 02 '15 at 12:26
  • When I run brew I get this error: $ brew doctor -bash: /usr/local/bin/brew: /bin/sh^M: bad interpreter: No such file or directory – olefrank Oct 02 '15 at 13:58

2 Answers2

3

This should bring back a working brew command:

cd /usr/local/Homebrew
git init
git remote add origin https://github.com/Homebrew/homebrew
git pull origin master

Next I would check the output of brew doctor and see if there are major problems. There is an official uninstalling guide on homebrew's github wiki in case you want to completely uninstall.

Devendra Bhatte
  • 319
  • 3
  • 17
cel
  • 24,830
  • 16
  • 80
  • 107
  • Fantastic! Seems to solve my problem. Could you please explain what was the problem? Your solution only downloads files to my hard drive. But how about relations to the OS? Like "Registry entries" on Windows... – olefrank Oct 02 '15 at 16:10
  • Well you already figured that out in your question. You deleted files which you should not delete. Homebrew is designed for mac, so I would not worry about applying the solution to windows. – cel Oct 02 '15 at 16:53
0

Try to move or remove the Homebrew file in the user/local file and then try the regular link from the homebrew homepage to install the brew!

By the way, I did not try moving but I am pretty sure it should work.

Note: While the operation you might have to use the sudo