Skip to content

Instantly share code, notes, and snippets.

@varenc
Last active April 18, 2023 10:29
Show Gist options
  • Save varenc/47c4b22e2b8c5afabce556645a90801d to your computer and use it in GitHub Desktop.
Save varenc/47c4b22e2b8c5afabce556645a90801d to your computer and use it in GitHub Desktop.
Homebrew patch to spoof a particular macOS version to allow you to force install pre-compiled binary bottles anywhere

Force brew to install pre-compiled binary bottles on older versions of macOS (Mojave).

This patch makes a small modification to Homebrew allowing you to "spoof" or override its perceived macOS version. Often compiled bottles will work fine on older unsupported macOS verisons and using a bottle means you don't have to compile a formula from scratch or download and compile its build-only dependencies.

Of course you shouldn't do this unless you're very familiar Homebrew internals and understand the limitations. Things make break in a very confusing way. Most users should just keep macOS up to date, but for those that can't this patch may be helpful.

To use, first download and install the patch:

$ cd "$(brew --repo)"
$ wget "https://gist.githubusercontent.com/varenc/47c4b22e2b8c5afabce556645a90801d/raw/homebrew_override_version.patch" --output-document=/tmp/homebrew_override_version.patch
$ git apply /tmp/homebrew_override_version.patch
$ git diff  # running this just shows you that the patch you expect has been applied.  Revert with `git checkout .` if not.

You can now override brew's percieved version by setting the env HOMEBREW_MACOS_VERSION_OVERRIDE. For example, on macOS Mojave you can pretend to be on Catalina like this:

$ HOMEBREW_MACOS_VERSION_OVERRIDE="10.15.7" brew install -dv fzf

This will "trick" brew into installing the Catalina compiled binary for fzf. Homebrew by default would have forced a Mojave user to install and compile go, and then use that to compile fzf. But in this case, the latest fzf Catalina binary works fine on Mojave. (of course this may break in the future)

diff --git a/Library/Homebrew/brew.sh b/Library/Homebrew/brew.sh
index cbe08846a..e3b3bba5c 100644
--- a/Library/Homebrew/brew.sh
+++ b/Library/Homebrew/brew.sh
@@ -425,7 +425,9 @@ then
HOMEBREW_PRODUCT="Homebrew"
HOMEBREW_SYSTEM="Macintosh"
[[ "${HOMEBREW_PROCESSOR}" == "x86_64" ]] && HOMEBREW_PROCESSOR="Intel"
- HOMEBREW_MACOS_VERSION="$(/usr/bin/sw_vers -productVersion)"
+
+ [ -z $HOMEBREW_MACOS_VERSION_OVERRIDE ] && HOMEBREW_MACOS_VERSION="$(/usr/bin/sw_vers -productVersion)" || HOMEBREW_MACOS_VERSION="${HOMEBREW_MACOS_VERSION_OVERRIDE}"
+
# Don't change this from Mac OS X to match what macOS itself does in Safari on 10.12
HOMEBREW_OS_USER_AGENT_VERSION="Mac OS X ${HOMEBREW_MACOS_VERSION}"
@rotkohlsuppe
Copy link

Thank you for this line of code!

Do you know how to overcome curl: (60) SSL certificate problem: certificate has expired
I have Mojave and I'm trying to spoof something 11+

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment