arm64 mac: how to keep two shell environments (with and without rosetta) organized

I'm using an M1 macbook air for programming work. There are many tools that need rosetta emulation, while others work much faster and more stable natively.
To deal with this I've set up a copy of the terminal, called it "Terminal Rosetta" and enabled that "open with rosetta" checkbox.

But a problem I'm facing is that lots of configuration is shared between those terminals. For example, there are some python libraries that don't work under arm64. So I've installed conda with an x64 installer in the rosetta terminal. But the native terminal also has conda environments now, without me installing anything there. And I can use conda to activate environments that definitely won't work without rosetta emulation.

So far I've used homebrew only in the rosetta terminal. But now there are some packages that I'd like to install in the native terminal. I'll need two homebrew environments in parallel.

I think the correct way to solve this is to have two separate zsh profiles and keep separate PATH variables for the two terminals. But I don't understand how I can set that up. Maybe using something other than the default terminal would be helpful.


If you open Terminal natively on your M1/Apple-Silion Mac and type uname -mp, you'll get something like:

arm64 arm

If you open Terminal with Rosetta and run that, you'll get:

x86_64 i386

You could use that command (or even just one of the options, "-m" or "-p") with IF/THEN logic in your shell profile script to change your PATH, etc, based on which environment you're in.


The comments from @jimtut have been very helpful (thanks a lot!).

If you're looking how to have branches in your shell config, here's some code that you can put into .zprofile:

#!/bin/zsh
 
arch_name="$(uname -m)"
 
if [ "${arch_name}" = "x86_64" ]; then
    if [ "$(sysctl -in sysctl.proc_translated)" = "1" ]; then
        echo "Running on Rosetta 2"
    else
        echo "Running on native Intel"
    fi 
elif [ "${arch_name}" = "arm64" ]; then
    echo "Running on ARM"
    eval "$(/opt/homebrew/bin/brew shellenv)"
else
    echo "Unknown architecture: ${arch_name}"
fi

If you're interested in having two separate homebrew installations, you should do the following:

  • run their installer twice, once in a rosetta 2 terminal, once in the native terminal
  • the two runs will create two installation directories. The x86 binaries are now in /usr/local and the arm ones are in /opt/homebrew
  • as far as I can see, the intel binaries are on PATH by default. But you can activate the arm ones to take precedence. So I've added the following line to my .zprofile, it's executed when the terminal is running on arm eval "$(/opt/homebrew/bin/brew shellenv)"

Now you have two version of brew and depending on whether your shell is emulated or native, the right one is on your PATH.