Background
One particular issue that I encountered when I tried to install some software using Homebrew on my Mac is that Homebrew deprecates support for older macOS versions just like Apple do. Once a macOS version is deprecated, Homebrew will not provide bottles (precompiled binaries) for that version. This means that you have to compile the software from source, which is extremely time-consuming and sometimes error-prone. Imagine installing shell-check
will require to build ghc
from source, which takes hours, and then use ghc
to build shell-check
from source. This is not a good experience.
Solution
Pin homebrew/core to an older version
One way to work around this issue is to use a older version of the homebrew/core
tap, such that the bottles are still available for the macOS version you are using because they are built when your macOS version is supported. The downside is that you will be using outdated software. If this is not an issue for you then congratulations. You can achieve this by running the following command:
|
|
Make sure you disable the auto-update of Homebrew so that it does not update the homebrew/core
tap to the latest version. You can do this by running the following command:
|
|
Fake macOS version
Another way is to fake the macOS version that Homebrew detects. This way, Homebrew will provide bottles for the macOS version you are faking. Most software will work and you will be using the latest software. However, this may not work for all software as some software may have dependencies that are not available for the macOS version you are faking. You can achieve this by running the following command:
|
|
Explanation
Homebrew actually has an private undocumented API that allows you to fake the macOS version. https://github.com/Homebrew/brew/blob/a3d8f4e0e4a22da9990d59cca70bec1e7be726cf/Library/Homebrew/os/mac.rb#L41
|
|
Example
I have macOS Monterey (12.0) running, which is just deprecated by Homebrew. I want to install batt
which is not available as a bottle for macOS Monterey.
If I run brew install batt
, I will get the following error:
|
|
It’s Oct 8, 2024 and the latest macOS version is macOS Sequoia (15.0). So the last 3 supported macOS versions are:
- macOS Sequoia (15.0)
- macOS Sonoma (14.0)
- macOS Ventura (13.0)
You can confirm that by checking out batt
’s formula:
|
|
Showing only the bottles for macOS Sequoia (15.0), macOS Sonoma (14.0), and macOS Ventura (13.0) are available.
Sadly my macOS version (Monterey 12.0) is not in the list, but macOS Ventura (13.0) is the closest to macOS Monterey (12.0). So I can fake the macOS version to macOS Ventura (13.0) by running the following command:
|
|
As you can see, Homebrew is downloading the bottle for macOS Ventura (13.0) successfully! (Of course, the log is showing that I have already downloaded earlier, but you get the idea.)
batt
itself does not rely on any APIs that are not available in my current macOS version, so it works perfectly fine.