I want to install and run two versions of Homebrew simultaneously on an Apple Silicon Mac: an ARM64 version, and an Intel version running under Rosetta 2.
I know I can prepend any brew command with arch --x86_64
to emulate Intel for that command, but this can lead to conflicts for formulas whose dependencies you already have built for ARM64. For example:
Error: gnupg dependencies not built for the x86_64 CPU architecture:
pkg-config was built for arm64
gettext was built for arm64
readline was built for arm64
[email protected] was built for arm64
How can I install and run two separate, isolated versions of Homebrew (one for native ARM64 and one for emulated Intel), keeping each of their installed formulae and dependencies separate?
But if you install Homebrew on an M1 Mac running Apple Silicon, then Homebrew gets installed in /opt/homebrew/bin . Since /opt/homebrew/bin is not included in your PATH by default, there is some extra configuration needed to allow you to use packages installed with Homebrew.
On Mac Intel, Homebrew installs itself into the /usr/local/bin directory, which is already configured for access by the shell with the macOS default $PATH environment variable (the default is set by the /usr/libexec/path_helper command).
Just like cargo build && cargo run creates a binary, stores it in a predictable location, and executes it, Homebrew creates executables and installs them into a predictable location for your computer to execute later.
Now that Homebrew is installed, use it to download a package. The tree command lets you see a graphical directory tree and is available via Homebrew. Homebrew will update its list of packages and then download and install the tree command: Homebrew installs files to /usr/local by default, so they won’t interfere with future macOS updates.
You can now use Homebrew to install command line tools, programming languages, and other utilities you’ll need for software development. Homebrew has many packages you can install. Visit the official list to search for your favorite programs. Want to learn more? Join the DigitalOcean Community!
Now let’s verify that Homebrew is set up correctly. Execute this command: If no updates are required at this time, you’ll see this in your Terminal: Your system is ready to brew. Otherwise, you may get a warning to run another command such as brew update to ensure that your installation of Homebrew is up to date.
Occasionally, you’ll want to upgrade an existing package. Use the brew upgrade command, followed by the package name: You can run brew upgrade with no additional arguments to upgrade all programs and packages Homebrew manages. When you install a new version, Homebrew keeps the older version around.
Install Homebrew natively on Apple Silicon in /opt/homebrew
:
mkdir homebrew && curl -L https://github.com/Homebrew/brew/tarball/master | tar xz --strip 1 -C homebrew
Install Intel-emulated Homebrew to the default /usr/local
:
arch --x86_64 /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)"
If you haven't yet installed Rosetta 2, you'll need to run softwareupdate --install-rosetta
first.
Create an alias for Intel homebrew. I'm calling mine brow
because O for old. But hey you do your own thing.
In ~/.zshrc
(or your shell's equivalent) add:
alias brow='arch --x86_64 /usr/local/Homebrew/bin/brew'
Add ARM Homebrew to your PATH.
In ~/.zshrc
(or your shell's equivalent) add:
# Homebrew on Apple Silicon
path=('/opt/homebrew/bin' $path)
export PATH
If you're still on bash
it'd be PATH=/opt/homebrew/bin:$PATH
Confirm
which brew
should return /opt/homebrew/bin/brew
brew --prefix
should return /opt/homebrew
which brow
should return brow: aliased to arch --x86_64 /usr/local/Homebrew/bin/brew
brow --prefix
should return /usr/local
If you have the same command installed in both Homebrews, it'll default to Apple Silicon (/opt/homebrew/
) since we prepended that one in our PATH. To override, run the command with its full path (/usr/local/bin/youtube-dl
), or override your PATH
for one command (PATH=/usr/local/bin youtube-dl
).
I also created another handy alias in .zshrc
(alias ib='PATH=/usr/local/bin'
) so I can prepend any Homebrew-installed command with ib
to force using the Intel version of that command:
~ ▶ which youtube-dl
/opt/homebrew/bin/youtube-dl
~ ▶ ib which youtube-dl
/usr/local/bin/youtube-dl
If you prefer Intel to be the default brew
, add /opt/homebrew/bin
to the end of your PATH instead of the beginning.
Install Native Homebrew
❯ arch --arm64 zsh -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)"
all Homebrew related stuffs are in /opt/homebrew
.
Install Rosetta Homebrew
❯ arch --x86_64 zsh -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)"
all Homebrew related stuffs are in /usr/local
.
Configuring ~/.zshrc
to use Brew
defaultly based on arch
,
# Multiple Homebrews on Apple Silicon
if [ "$(arch)" = "arm64" ]; then
eval "$(/opt/homebrew/bin/brew shellenv)"
export PATH="/opt/homebrew/opt/[email protected]/bin:$PATH"
# export LDFLAGS="-L/opt/homebrew/opt/[email protected]/lib" # For compilers to find [email protected]
else
eval "$(/usr/local/bin/brew shellenv)"
export PATH="/usr/local/opt/[email protected]/bin:$PATH"
export PATH="/usr/local/opt/[email protected]/bin:$PATH"
# export LDFLAGS="-L/usr/local/opt/[email protected]/lib" # For compilers to find [email protected]
fi
Test
❯ arch
arm64
❯ which brew
/opt/homebrew/bin/brew
❯ arch -x86_64 zsh
❯ arch
i386
❯ which brew
/usr/local/bin/brew
# set alias as you like
❯ rzsh='arch -x86_64 zsh'
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With