How to set Brew 4 to use upstream JSON downloads

During regular stack updates in March of 2023, Brew has been upgraded to version 4.

Homebrew 4.0.0 There is a significant increase in package repository update speed from their changes, if you require the very latest package versions available.

However, for stability and for increased build performance by default the macOS VMs have brew installed but the main source is changed from the official GitHub - Homebrew/homebrew-core to the Bitrise maintained mirror

To maintain our mirrors, and retain the “frozen” brew behaviour, we have set the environment variable HOMEBREW_NO_INSTALL_FROM_API=1 on our stacks

If for some reason you’d need a brew formulae that’s so new that it’s not available in the Bitrise mirror, or if you’d need a newer version of the formulae that’s not yet available in the Bitrise mirror you can use a Script step to unset the above environment variable. Brew will then pull JSON packages from their API.

This will be significantly quicker than setting the Brew git mirror back to upstream as was the behaviour for Brew 3.x.x (How to change brew core from mirror to official?)

1#!/usr/bin/env bash
3set -ex
7brew update
9# or if you just want to upgrade

The environment variable HOMEBREW_NO_INSTALL_FROM_API is set in the .bashrc and the .zshrc config files in the vagrant user’s home directory.