There are numerous guides for downgrading a Brew package but somehow, none that I tried I found to be particularly helpful, let alone working and straightforward. Thus I mixed and matched them together to build Yet another brew downgrade package guide™, that at least works for my needs. Start by cloning a brew core repository:
git clone https://github.com/Homebrew/homebrew-core
Now get in to correct folder where your expected formula resides, deep inside the letter folder:
cd homebrew-core/Formula/n
Get the correct hash of the commit containing desired version, install
tig
via brew if missing:
tig neovim.rb
You can either write the short hash manually or you can copy it via the
following keybinding, edit ~/.config/tig/config
:
bind generic 9 !@sh -c "git rev-parse --short %(commit) | pbcopy"
When on desired commit press 9
and the short commit hash will be in your
clipboard. Now checkout that commit, pasting or writing the hash:
git checkout 1a2b3b4d
And herein lies the magic, install the package:
brew install neovim.rb
The last thing you can do is to pin the package:
brew pin neovim
Pinning will prevent upgrading the package again in the future. You can check list of pinned packages via:
brew list --pinned
Now use brew as before, if you want an automatic upgrade of the package, just unpin it:
brew unpin neovim
Simple.
Troubleshooting
Make sure to not make a mistake of omitting the .rb
extension. Another
thing that took me quite a while to figure out was to actually cd
into
containing folder and not to use any path in brew install
, in other
words:
git clone https://github.com/Homebrew/homebrew-core
cd homebrew-core
brew install Formula/n/neovim.rb
Above will likely cause a highly confusing error:
==> Tapping formula/n
Cloning into '/opt/homebrew/Library/Taps/formula/homebrew-n'...
Username for 'https://github.com':
The reason for this error is that of course the repository
https://github.com/Formula/homebrew-n
does not exist publicly. If such
repository existed the error would likely be different, but I did not get
that far. I was able to get a hint of a problem via -dv
switch:
brew install -dv Formula/n/neovim.rb
Which produces a little bit more details about the ongoing operation:
/opt/homebrew/Library/Homebrew/brew.rb (Formulary::FromTapLoader): loading Formula/n/neovim.rb
/usr/bin/env /opt/homebrew/Library/Homebrew/shims/shared/git --version
==> Tapping formula/n
git clone https://github.com/Formula/homebrew-n /opt/homebrew/Library/Taps/formula/homebrew-n --origin=origin --template= --config core.fsmonitor=false
Cloning into '/opt/homebrew/Library/Taps/formula/homebrew-n'...
Username for 'https://github.com':
The third common problem I have encountered looks like this:
$ brew install zola.rb
==> Downloading https://formulae.brew.sh/api/formula.jws.json
##O=-# #
Error: Failed to load cask: zola.rb
Cask 'zola' is unreadable: wrong constant name #<Class:0x0000000122484108>
Warning: Treating zola.rb as a formula.
Error: zola 0.19.1 is already installed
To install 0.18.0, first run:
brew unlink zola
But running what the error suggest was enough for me to resolve the issue:
brew unlink zola
brew install zola.rb
Enjoy!