70

I am using the terminal on an Apple M1 MacBook. I try to use a cli tool that is not build for aarm64, so I get this error message in the terminal:

zsh: bad CPU type in executable

Is there anything I can do to use this cli tool e.g. with emulation or something? How can I run binaries on a M1 based Mac in the Terminal that is not natively built for Arm?

0

3 Answers 3

105

When macOS tries to run an app that is not built for Apple silicon, macOS will prompt to install Rosetta 2 to automatically translate the app to Apple silicon.

In Terminal, there is no automatic detection for missing Rosetta to run older architecture command line tools.

If you haven't been prompted for any other app already, manually install Rosetta 2:

softwareupdate --install-rosetta

If you need to run a universal binary in the previous architecture, use arch and specify the architecture. You need to manually specify the architecture for binaries that need to run other binaries that are not built for Apple silicon, like Homebrew.

arch -x86_64 …

e.g. arch -x86_64 brew install packagename

Alternatively, you can run the entire Terminal app using Rosetta by opening Get Info on Terminal.app in Finder and checking ‘Open using Rosetta’. This way will Terminal and every binary it tries to run through Rosetta, so Apple silicon binaries won't be supported and performance will be impacted, but you don't need to specify the architecture to run old binaries.

To switch an existing zsh terminal to x86_64 use this command:

arch -x86_64 zsh
8
  • Is there no support for something like binfmt in Linux? Dec 9, 2020 at 10:22
  • @DmitryGrigoryev Even binfmt needs handlers for the different formats. Installing Rosetta will add the functionality required to run Intel code on M1.
    – nohillside
    Dec 9, 2020 at 23:22
  • 1
    @DmitryGrigoryev What makes you think it works otherwise on macOS (even if the kernel functions are called differently)? Unless Rosetta is installed, Big Sur/M1 can't execute Intel code. Once it is, the OS will pick the right binary automatically, the arch command can be used to override that (as can the checkbox in Finder).
    – nohillside
    Dec 10, 2020 at 12:42
  • 1
    I am getting the same error (zsh: bad CPU type in executable) when I run the command arch -x86_64 zsh (I have installed rosetta) Jan 7 at 21:22
  • 1
    @SametBaskıcı - you might want to refer the exact path towards your zsh binary arch -x86_64 /bin/zsh
    – amiabl
    Feb 21 at 14:45
2

If you are running: arch -x86_64 zsh (or similar) and get this error, try running

which -a zsh

to check your zsh installations. I ended up with

/opt/homebrew/bin/zsh
/bin/zsh

and needed to

brew uninstall zsh

to get just one, then the arch command worked for me.

-2

If you are facing this error when installing Homebrew on mac. Follow these steps:

  1. Open a new Terminal session.
  2. Remove /usr/local/bin from PATH for this session by PATH=${PATH/\/usr\/local\/bin:}
  3. Run which git curl in this session.
  4. Confirm that you get no errors and neither path reported begins with /usr/local/bin
  5. Run the installer in this session.

Source: https://github.com/Homebrew/discussions/discussions/1379#discussioncomment-672727

2
  • 4
    The question is about the error message in general, not about installing Homebrew on an M1 installation migrated from Intel.
    – nohillside
    Feb 26, 2022 at 5:51
  • added details for if Homebrew install has problem then follow these steps. May 14 at 1:52

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .