1

My macOS 14.2.1 (Darwin 23.2.0) is arm64 by default. I set up a bunch of x86_64 versions for different apps (have Rosetta 2 set up as well). For example, cmake and Homebrew. But when I call them with arch -x86_64 prefix, the OS cannot find them:

arch -x86_64 cmake
arch: posix_spawnp: cmake: Bad CPU type in executable

The following thing works though:

arch -x86_64 /usr/local/Homebrew/Cellar/cmake/3.31.4/bin/cmake

The same is with the other apps installed for x86_64. Even when I call arch -x86_64 zsh and switch my bash to the x86_64 mode, it can't find the paths. When I call

which cmake

It always shows only one path (arm64), either when I'm on arm64 or x86_64 version of zsh:

/opt/homebrew/bin/cmake

Should I manually add all paths to the x86_64 applications to $PATH or is there a better way to tell the OS to do this automatically?

nohillside
108k43 gold badges230 silver badges291 bronze badges
asked Jan 15 at 17:06

1 Answer 1

1

macOS has the concept of universal binaries, which basically are binaries which include both the ARM and the X86 version of the code (check with file /bin/sh). For these binaries, arch -x86_64 BINARY will work as you expect. But as you found out, Homebrew-installed binaries are not universal (run file {/usr/local,/opt/homebrew}/bin/cmake to check).

Adding both directories to PATH will not help because arch will still pick the first one, not the first one matching the architecture. This is also documented in man arch: "The other use of the arch command is to run a selected architecture of a universal binary."

In your situation, I probably would start a dedicated x86_64 shell and use the shell startup scripts to set the path depending on the architecture:

case $(arch) in
 arm64) PATH=/opt/homebrew/bin:$PATH
 ;;
 x86_64) # this may not be required if /usr/local/bin is in PATH anyway
 PATH=/usr/local/bin:$PATH
 ;;
esac

Alternatively, you could use a shell function to start x86 binaries:

function run86() {
 cmd=1ドル
 shift
 arch -x86_64 /usr/local/bin/${cmd} "$@"
}
answered Jan 15 at 17:53
2
  • Thanks for your answer! Is there a way to install an app as universal? In my case brew install cmake would only install an arm64 version and arch -x86_64 /usr/local/Homebrew/bin/brew cmake would only install an x86_64 one. Commented Jan 16 at 7:42
  • @AntonSerov Homebrew-installed binaries are not universal (Homebrew casks may be, depending on how the provider compiles them). If you want to have universal command line tools, you may need to compile them yourself. Commented Jan 16 at 8:18

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.