Updating Homebrew from Sierra age in macOS Mojave

So, long story short, I've had no issues with Homebrew since upgrading from macOS Sierra to macOS High Sierra to now macOS Mojave, but that's probably because I don't use it that often!

I think the only few times I used Homebrew is back in macOS Sierra when I first installed it. I used it to install all kinds of softwares, like gedit, pyenv, and so on. And that's it, I never update Homebrew or the softwares installed using Homebrew (or maybe I did update them for a few times, but obviously chances were very close to 'never' since I cannot even remember the last time I used Homebrew!)

So, out of nowhere, today I just decided to upgrade gedit!

And in the process I decided to update Homebrew as well, cuz why not, what could possibly go wrong ;)

None surprisingly, I got some errors. Such as:

Error: Your Xcode (1) is too outdated.
Please update to Xcode 9.0 (or delete it).
Xcode can be updated from
  https://developer.apple.com/download/more/

Error: Your Command Line Tools are too outdated.
Update them from Software Update in the App Store.

Or like this:

error: https://github.com/Homebrew/brew.git did not send all necessary objects

That does not make sense since I use the latest version of Xcode and I did not have auto-discover-proxy enabled in network settings!

After some Google search, here is what works for me.

First, run:

$> cd "$(brew --repo)" && git fetch && git reset --hard origin/master && brew update

After this, your shell may not be able to find Homebrew:

$> brew -v
zsh: command not found: brew

No worries, let's reinstall it, oh by the way, if you run that ruby -e xxxx Homebrew installation command it will give you this warning:

Warning: The Ruby Homebrew installer is now deprecated and has been rewritten in
Bash. Please migrate to the following command:
  /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)"

So better run:

$> /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)"

The installation script will need admin password, then the installation process will start. Here I saw my Homebrew version was 1.3.1! Yikes, that's probably from back in year 2017 or 2018!

After installation, my Homebrew version is

$> brew -v
Homebrew 2.3.0 

Looks pretty good, let's now finally upgrade gedit!

$> brew upgrade gedit

And it downloaded a massive amount of dependencies of sort and made me wonder if I really need to upgrade gedit in the first place. Because everything was running so smoothly right before I decided to do something stupid and unnecessary.

I wrote something with similar points in a previous blog: MacOS is a darn good system, until it drives you crazy.

So yeah, now I have upgraded gedit from 3.22.1 to 3.36.2 and what do I get? The auto-highlighting no longer works for .zshrc file, and the font and font size are all funny. Nice :-(

Anyway, I decided while I am at it, I should probably update a bunch of outdated softwares, starting with pyenv since I use that a LOT:

$> brew upgrade pyenv

And now pip don't work no more...

Apparently, after upgrading pyenv, it might cause pip (from previous Python installed by old pyenv) to give error: pip is configured with locations that require TLS/SSL, however the ssl module in Python is not available.

Luckily I was able to resolve this issue by re-installing the Python version that caused the problem. In my case. it is 3.6.4.

$> pyenv install 3.6.4

Rest assured, your existing pyenv environments that were based on the Python version which went wrong will not get affected, IMO, this is just re-installing the Python interpreter.

And that's pretty much it, I thought I should write a blog about this in the hope that it might help others in future so here we are.