1

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.

2
  • 1
    Check with the homebrew community to see if they support dual installs on your Mac. It seems like it should be possible, but I seem to remember somethings saying that they did not support it. But for the rest of the shell configuration, you can just put IF/THEN statements in your shell profile to configure your environment differently depending on which Terminal you are in.
    – jimtut
    Aug 10, 2021 at 10:48
  • Brew seems to work relative to its installation directory. Having two separate installations should be as easy as just installing to twice. But I don't know how I can have multiple zsh configs or how to check whether I'm running on rosetta
    – lhk
    Aug 10, 2021 at 13:27

2 Answers 2

1

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.

1

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.

You must log in to answer this question.

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