Now you have an own x86 installation of brew at: /usr/local/Homebrew
Add the following lines to your ~/.zshrc →
# arch and homebrew setup
PATH_BREW_X86_64="/usr/local/Homebrew/bin"
PATH_BREW_ARM64="/opt/homebrew/bin"
if [[ $(arch) = "arm64" ]]; then
# add your own arm64 specific stuff here
export PATH="$PATH_BREW_ARM64:$PATH"
else
# add your own x86 specific stuff here
export PATH="$PATH_BREW_X86_64:$PATH"
fi
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.
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.
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.
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 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
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
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:
Note that you must install Rosetta 2 if another x86_64 application hasn’t installed it already, with
softwareupdate --install-rosetta
Also I don’t think a x86_64 installation of Homebrew is required. Rack’s build system doesn’t link to any brew libraries, and you can run arm64 binaries inside the x86_64 shell.
Hi, I have a problem that appears when I try this command: I get this output:
Press **RETURN** to continue or any other key to abort:
**==>** **/usr/bin/sudo /usr/sbin/chown -R jeffgreenlee:admin /usr/local/Homebrew**
**==>** **Downloading and installing Homebrew...**
HEAD is now at 2ae21a582 Merge pull request #12803 from Homebrew/dependabot/bundler/Library/Homebrew/zeitwerk-2.5.4
Error: Failed to link all completions, docs and manpages:
Permission denied @ rb_file_s_symlink - (../../../Homebrew/completions/zsh/_brew, /usr/local/share/zsh/site-functions/_brew)
Failed during: /usr/local/bin/brew update --force --quiet
did you set your environment for x64 ? Else it will try to maake an ARM64 brew env, and that won’t help to build plugins. It is documented here: Develop Rack x86/64 on M1 Mac
but apparently, Brew install is running into some file/directory permissions issues!!! I tried to precede the command with “sudo”. but then I just get a message “Don’t run this as root!”
hmmm, woked like a charm here that doc I linked. Had it running forever and don’t remember any issues. Did you turn on the option to install Apps from other devs in the security widget in System Preferences? Also check permissions for yourself to modify /usr/local as that is where brew installs itself.