26
Oct 2015
On Computer Technology
Roughly 2 weeks ago I was writing a Bash script to automate some stuff, one of them being installing brew. To test if this script was working, I needed to uninstall brew. So I googled for it and came across the homebrew FAQ which says to run the following:
ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/uninstall)"
which I did.
Then I proceeded to run my script, which contains the following line of code (from the brew website) to install brew:
ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
However, this command caused the following error:
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)"
Ok, I thought I uninstalled brew already. Never mind, maybe the uninstallation script went wrong. So I ran it again:
ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/uninstall)"
and if memory serves (after all, it was about 2 weeks ago), I got the following error:
Failed to locate Homebrew!
Ok… let’s install brew again:
ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
and I got the same error again:
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)"
Wtf.
Refusing to believe this, I probably went through the cycle at least 2 more times. I have seen and know the definition of insanity, which is:
doing the same thing over and over again and expecting different results.
and I was definitely not insane. So to solve this problem, I had to do something different. I googled around but couldn’t find anything helpful. After some time, the following thought firmly presented itself in my mind: I screwed up my brew installation and there is a chance I won’t be able to install brew again.
But I needed brew back. And while there is indeed a chance that I screwed things up so bad that I wouldn’t be able to install brew ever again, that’s a pretty slim chance. I knew for a fact that brew was uninstalled, because 1. brew itself was gone and 2. all the programs that were installed using brew were gone as well. So the uninstallation mostly worked properly. The script that fucked up was probably the installation script. I knew that I’d have to look inside the brew installation script to see what went wrong. Kind of intimidating. I was also pretty tired and needed a break, so I went for one.
After my break, I downloaded the brew installation script file. Ok. So it’s over 200 but below 300 line of ruby code. Not so intimidating after all. Then I looked around for text that resembled the above error I got that complained about brew being installed on my system. And I found it! Here’s how the ruby code looked like:
abort <<-EOABORT unless Dir["#{HOMEBREW_PREFIX}/.git/*"].empty?
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)"
EOABORT
Hmm, so to trigger this abort, Dir["#{HOMEBREW_PREFIX}/.git/*"].empty?
must be false. So what is HOMEBREW_PREFIX
? Turns out it’s defined right at the top of the brew installation script as /usr/local
. Ok, so /usr/local/.git
must be present on my mac. And indeed it is. That’s the cause of the error. And indeed it looks like a .git
directory whenever one clones a git repository. Let’s remove it:
rm -rf /usr/local/.git
And run the brew installation script:
ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
which worked flawlessly this time.
What did I learn from this?
Disclaimer: Opinions expressed on this blog are solely my own and do not express the views or opinions of my employer(s), past or present.