Switching Homebrew between x86 and ARM

Published
Updated

When installing and configuring Homebrew on a MacBook that has an M1 / M2 (ARM) chip, you will need to have a separate version of Homebrew for any packages that rely on x86.

Keep in mind, if you already have only installed Homebrew using the default (ARM) version, trying to compile anything that relies on an x86 version will probably give you an error that a dependency is missing or you will get a build error such as Symbol(s) not found for architecture arm64.

Installing the x86 version of Homebrew for Mac M1 / M2

Running the following will install the x86 version of homebrew into /usr/local/homebrew:

arch -x86_64 /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"

Switching between Homebrew ARM and x86

You can easily switch to the ARM version of homebrew by running the following:

# Switch to ARM homebrew
eval "$(/opt/homebrew/bin/brew shellenv)"

Use the following to switch back to the x86 version:

# Switch to x86_64 homebrew
eval "$(/usr/local/homebrew/bin/brew shellenv)"

M1 Macs - switching the terminal between ARM and x86

Oftentimes you will encounter the following errors if your terminal is in x86 but you are referencing an ARM installation of Homebrew (or vise versa):

Error: Cannot install in Homebrew on ARM processor in Intel default prefix (/usr/local)!
  • This means that you are attempting to reference the Intel version /usr/local of your Homebrew installation while using the ARM architecture.

To solve this, just prefix your brew command like in the following command:

arch -x86_64 brew install some-package
Error: Cannot install in homebrew on intel processor in arm default prefix (/opt/homebrew)!
  • This is a similar issue as described above, except the processor and the home brew install versions have been swapped. You can solve this by prefixing your brew command like so:
arch -arm64 brew install some-package