Configuring macOS Terminal for both x86 and ARM on Apple Silicon Devices

Tags mac x86

Summary

It's possible to configure macOS terminal to automatically start using x86 emulation. You can pair this with 2 miniconda installs, one for each architecture, and a custom .condarc profile to auto-launch the appropriate version based on the current profile/architecture.

Please note: If you use MacPorts, you only need the 1 installation; there is no separate versions for arm/x86. Just be aware that when calling the port command when in x86, it can overwrite an existing ARM port. I do not believe it installs these in differnet locations based on the architecture. Use with caution. If desired, 2 versions of homebrew can be installed and variables set for each within your .zshrc file.

Environment

  • macOS
    • Terminal
  • Apple ARM Processors
  • Anaconda/Miniconda/Conda

Directions

Creating Profiles

  1. Open Terminal
  2. Click Terminal in the top menu bar and select Settings
  3. Select the Profiles option at the top of the resulting window
  4. Add a new profile (or modify the default) and name it ARM
  5. Add another profile and label it x86
  6. In the "Window" tab, set the title to something like "x86 Terminal" and uncheck all boxes under the title section (if desired)
  7. Switch to the Shell tab and select the Run Command checkbox
  8. Enter the following in the input field: arch -x86_64 zsh
    • Customize the colors or other settings as desired to help visually differentiate between shells

A Note on Install Locations

While we'll be installing Conda at the user level, other installs may be system wide, such as homebrew or macports. In general, the install path based on architecture is as follows:

  • /usr/local for x86
  • /opt/local for arm

e.g. /usr/local/brew for x86 homebrew, /opt/local/brew for arm

Installing Conda for Each Architecture

Grab the latest version of Miniconda for the corresponding architecture, then within each profile, run the corresponding install script:

ARM

Please note: the very last prompt in the install script about initializing conda should be answered with "no".

$ curl -O https://repo.anaconda.com/miniconda/Miniconda3-latest-MacOSX-arm64.sh
$ chmod ug+x Miniconda3-latest-MacOSX-arm64.sh
$ ./Miniconda3-latest-MacOSX-arm64.sh
    When prompted for install location: $HOME/miniconda3
    When prompted to initialize: no

x86

Please note: the very last prompt in the install script about initializing conda should be answered with "no".

$ curl -O https://repo.anaconda.com/miniconda/Miniconda3-latest-MacOSX-x86_64.sh
$ chmod ug+x Miniconda3-latest-MacOSX-x86_64.sh
$ ./Miniconda3-latest-MacOSX-x86_64.sh
    When prompted for install location: $HOME/miniconda3_x86
    When prompted to initialize: no

Configuring conda init

We need to tell conda which version to activate based on the current shell architecture. To do this, we create a custom .condarc file and add to the .zshrc file.

Create the .condarc file

$ cd
$ mkdir .custrc
$ vim .custrc/.condarc

Please note: make sure to change the conda_path_m1 and conda_path_intel in the text below if you did not use the path's as outlined previously:

init_conda() {
   # >>> conda initialize >>>
   conda_path_m1="$HOME/miniconda3"
   __conda_setup="$('${conda_path_m1}/bin/conda' 'shell.zsh' 'hook' 2> /dev/null)"
   if [ $? -eq 0 ]; then
      eval "$__conda_setup"
   else
      if [ -f "${conda_path_m1}/etc/profile.d/conda.sh" ]; then
          . "${conda_path_m1}/etc/profile.d/conda.sh"
      else
          export PATH="${conda_path_m1}/bin:$PATH"
      fi
   fi
   unset __conda_setup
# <<< conda initialize <<<
}
init_conda_intel() {
   # >>> conda initialize >>>
   conda_path_intel="$HOME/miniconda3_x86"
   __conda_setup="$('${conda_path_intel}/bin/conda' 'shell.zsh' 'hook' 2> /dev/null)"
   if [ $? -eq 0 ]; then
      eval "$__conda_setup"
   else
      if [ -f "${conda_path_intel}/etc/profile.d/conda.sh" ]; then
          . "${conda_path_intel}/etc/profile.d/conda.sh"
      else
          export PATH="${conda_path_intel}/bin:$PATH"
      fi
   fi
   unset __conda_setup
   # <<< conda initialize <<<
}

Add to .zshrc

$ cd
$ vim .zshrc
# init conda based on arch
source ~/.custrc/.condarc
if [[ $(uname -m) == 'x86_64' ]]; then
    init_conda_intel
    echo "conda x86_64 is activated"
    # uncomment following line if using homebrew
    # eval "$(/usr/local/bin/brew shellenv)"
else
    init_conda
    echo "conda m1 is activated"
    # uncomment following line if using homebrew
    # eval "$(/opt/homebrew/bin/brew shellenv)"
fi

All that should be left to do from here is source the .zshrc file or open up a new terminal window using either the arm or x86 profile.

Details

Article ID: 10245
Created
Fri 6/2/23 3:35 PM
Modified
Tue 12/19/23 1:42 PM