Develop Rack x86/64 on M1 Mac

Hi all,

this is a micro-guide how to easily develop Rack x86 on M1 arm64 arch based Macs.

Install x86 version of Homebrew →

  1. Open iTerm2 or Terminal app and switch to x86 version of zsh:

    • arch -x86_64 zsh (I made an alias for this, for easy switching)
  2. Install brew (it does not matter, if you already installed brew on a arm64 terminal)

    • /bin/bash -c "$(curl -fsSL"
    • Now you have an own x86 installation of brew at: /usr/local/Homebrew

Add the following lines to your ~/.zshrc

# arch and homebrew setup

if [[ $(arch) = "arm64" ]]; then
    # add your own arm64 specific stuff here 
    export PATH="$PATH_BREW_ARM64:$PATH"
   # add your own x86 specific stuff here
    export PATH="$PATH_BREW_X86_64:$PATH"

This should behave like a normal Intel Mac installation, I did not encounter any issues so far, Rosetta2 is a great and robust thing. You may add a hint or something to your prompt on which arch you are currently, or use a different Terminal for this - else things may get confusing. (I added a small prefix to my zsh prompt which says arm or x86.)

I hope this helps M1 loving developer who struggled with such issues. It has been written down out of my memory, so I hope it is correct, let me know if there are any issues.

Cheers, Patrick.


Hey Patrick. Can you explain the difference here, is this also meant for installing RACK on ARM and bypass Rosetta?

Thanks for your efforts. Loving the M1 and happy to see developers embrace it.

Hi Jeroen,

this is basically intended for developers who want to seamlessly continue developing Rack modules on a M1 arm64 based machine. But also takes care of enabling development of native arm64 applications, depending on which environment you are. Running a shell with: arch -x86_64 zsh just switches to Rosetta2 emulation which behaves just like a normal x86 based environment. This guide also solves the problem of having two installations of brew on one machine, depending on the architecture, because Rosetta2 is not able to handle such complex package manager issues.

In a nutshell: You can continue normal developing of Rack modules but not locked out to work with native arm64, this isn’t working out of the box with brew.

Currently there is no official port of Rack for arm64 available, but you may take a look at an experiment version ported by me:

I hope this helps to get a better understanding for what this guide is intended to.

Cheers, Patrick.

1 Like

Is brew located in different directories for a AMD64 installation and an ARM64 installation? If not I find it difficutlt to see how they can co-exist on the same machine.

Yep, that’s the whole trick (and why your .zshrc have to be updated):

# arch and homebrew setup
1 Like

I guess my question is: Are those the directories that respectively ARM64/AMD64 brew installations live in naturally/normally, or are you forcing them to go there by setting those environment variables before installing brew?

Thank you so much, that clears things up tremendously. And of course, I saw your Rack.arm64 build :slight_smile: Really interested to see what it can do if we delve deeper into those CPUs.

Sorry for the late response, struggled a bit with different stuff :stuck_out_tongue_winking_eye:

Fortunately brew detects arm64 based systems and will install to a different path as it would do on a x86 system - I guess exactly for that reason. The only thing you have to take care about, is that after you installed standard brew for arm64, you have to remove the path variable, else brew won’t install in a x86 terminal.

IMPORTANT: I forgot in my tutorial that you have to clean the path variable after installing brew - it will be set later conditionally.

I hope this helps for understanding so far, Cheers, Patrick

1 Like

Ok, so on an M1 machine, when you install brew normally it’s installed in /opt/homebrew/bin, and after that, when you want to install the AMD64 version of brew, you have to remove /opt/homebrew/bin from your PATH first. After having installed both you control which brew install to use, by prepending the right one to the PATH, as you have shown above. Correct?

Yes, exactly. The only drawback I do noticed so far, is that you you mess around with pointers and accidentally run into a bad access (SEGFAULT etc.) you got no crash-report by macOS, I guess because it runs via Rosetta2. But lldb works fine and give you more info if you run into undiscovered crashes.

BTW.: My setup based on this article, which is quite similar:

Cheers, Patrick

1 Like