Wanna see something cool? Check out Angular Spotify 🎧

Error: Cannot install in Homebrew on ARM processor in Intel default prefix (/usr/local)

Problem

I am setting my MacOS fresh again and setting up my terminal. I wanted to use neofetch to get a nice-looking terminal prompt. But upon running brew install neofetch, I got the following error:

Error: Cannot install in Homebrew on ARM processor in Intel default prefix (/usr/local)!
Please create a new installation in /opt/homebrew using one of the
"Alternative Installs" from:
  https://docs.brew.sh/Installation
You can migrate your previously installed formula list with:
  brew bundle dump

Error: Cannot install in Homebrew on ARM processor in Intel default prefix (/usr/local)

Apparently, this happens because I am using a Mac M1 with an ARM processor. As explained on stackoverflow

Homebrew needs to be installed in two places on Apple silicon:

  • /usr/local for rosetta-emulated (Intel) code,
  • /opt/homebrew for ARM64 (M1).

These are somewhat hard-coded and the /opt/homebrew one MUST be used for ARM code and is non-negotiable

How I solved it

Following those steps below fixes the error for me.

  1. Install Rosetta2
/usr/sbin/softwareupdate --install-rosetta --agree-to-license
  1. Install Homebrew for ARM M1 chip
arch -x86_64 /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)"
  1. Once installed homebrew for M1 ARM, use this Homebrew command to install packages. Noted the prefix arch -x86_64
arch -x86_64 brew install <package>

I ran the following for my use case above for neofetch.

arch -x86_64 brew install neofetch

I can then install neofetch as expected.

Error: Cannot install in Homebrew on ARM processor in Intel default prefix (/usr/local)

Next Steps

In the comment, rahul suggested that you should add an alias to your .zshrc file for future convenience.

alias alias brew86="arch -x86_64 /usr/local/homebrew/bin/brew"

Therefore the above install command will become

- arch -x86_64 brew install neofetch
+ brew86 install neofetch

⚠️ Because zsh runs the binary in /usr/local/bin by default. Running brew86 will probably change the location newly installed application to /usr/local/homebrew/bin/brew.

You must also add the following to .zshrc so that zsh recognizes the binary in the new location.

export PATH="/usr/local/homebrew/bin:$PATH"

Otherwise, you’ll see some errors like this:

zsh: command not found: pyenv

Error: Cannot install in Homebrew on ARM processor in Intel default prefix (/usr/local)

Published 11 Jun 2022

    Read more

     — /usr/local/bin/code: line 6: python: command not found
     — Multiple ng-content
     — My React Reading List
     — Slick - prevent layout shift for your slider
     — CSS div jumped when adding a border

    Follow @trungvose on Twitter for more!