Luc Shelton

Homebrew and Anaconda: Configuring for Apple M1 and Intel Silicon

Homebrew and Anaconda: Configuring for Apple M1 and Intel Silicon

Homebrew and Anaconda: Configuring for Apple M1 and Intel Silicon

Homebrew and Anaconda: Configuring for Apple M1 and Intel Silicon

5 Minute(s) to read
Posted 24 months ago Updated 24 months ago 5 Minute(s) to read 296 comments

This is a quick article that will serve as a brain dump for how I've recently configured my /bin/bash profile for using Homebrew Package Manager with both M1 and Intel Silicon (with x86 emulated using Rosetta).

Installation Locations

Depending on which CPU architecture you are installing Homebrew Package Manager with will determine where brew is installed. By default, brew will be installed to the following locations.

M1 Silicon Installation Path

If you are using brew on Apple M1 silicon, then the default installation script will install Homebrew Package Manager to the following paths.

#!/bin/bash
/opt/homebrew/bin
/opt/homebrew/Caskroom

Intel Silicon Installation Path

If you are using Homebrew Package Manager on Intel silicon, or through Rosetta emulation, then you will notice that Homebrew is installed to the following paths when you use the default installation script that is available from the official homepage.

#!/bin/bash
/usr/local/bin/brew
/usr/local/Caskroom

Configuring Bash

Now that we know where brew is installed, we can configure bash to automatically load the relevant shell environment depending on which architecture is being used. This is useful if you have multiple copies of iTerm2 (for example), whereby one copy may be configured to launch with Rosetta emulation. If your Terminal instance (including iTerm2) is launched with Rosetta emulation, it will automatically attempt to use Homebrew at the listed installation path above (under "Intel Silicon"). However, because both installations are at different paths, we need some logic to detect which architecture (emulated or not) is being actively used, so we know which shell environment to load.

Refer to the logic below. It uses a command called "uname" to detect which CPU architecture is actively in use. Based on the resulting value, it will then load the relevant shell environment. x86_64 is considered to be Intel Silicon, and arm64 is considered to be Apple M1.

Homebrew Shell Environment

The snippet below describes the logic for automatically loading Homebrew shell environment depending on the architecture.

#!/bin/bash
if [[ "$(uname -m)" == "x86_64" ]]; then
	echo "Loading: Homebrew (x86)"
	eval "$(/usr/local/bin/brew shellenv)"
    CONDA_BREW_PATH=/usr/local/Caskroom/miniconda
else
	echo "Loading: Homebrew (ARM)"
	eval "$(/opt/homebrew/bin/brew shellenv)"
    CONDA_BREW_PATH=/opt/homebrew/Caskroom/miniconda
fi

Anaconda Shell Environment

The snippet below describes the logic (typically generated by Anaconda) for loading the relevant shell environment.

#!/bin/bash
if [[ "$(uname -m)" == "x86_64" ]]; then
    # >>> conda initialize >>>
    # !! Contents within this block are managed by 'conda init' !!
    __conda_setup="$('/usr/local/Caskroom/miniforge/base/bin/conda' 'shell.bash' 'hook' 2> /dev/null)"
    if [ $? -eq 0 ]; then
        eval "$__conda_setup"
    else
        if [ -f "/usr/local/Caskroom/miniforge/base/etc/profile.d/conda.sh" ]; then
            . "/usr/local/Caskroom/miniforge/base/etc/profile.d/conda.sh"  # commented out by conda initialize
        else
            export PATH="/usr/local/Caskroom/miniforge/base/bin:$PATH"  # commented out by conda initialize
        fi
    fi
    unset __conda_setup
    # <<< conda initialize <<<
elif [[ "$(uname -m)" == "arm64" ]]; then
    # >>> conda initialize >>>
    # !! Contents within this block are managed by 'conda init' !!
    __conda_setup="$('/opt/homebrew/Caskroom/miniforge/base/bin/conda' 'shell.bash' 'hook' 2> /dev/null)"
    if [ $? -eq 0 ]; then
        eval "$__conda_setup"
    else
        if [ -f "/opt/homebrew/Caskroom/miniforge/base/etc/profile.d/conda.sh" ]; then
            . "/opt/homebrew/Caskroom/miniforge/base/etc/profile.d/conda.sh"  # commented out by conda initialize
        else
            export PATH="/opt/homebrew/Caskroom/miniforge/base/bin:$PATH"  # commented out by conda initialize
        fi
    fi
    unset __conda_setup
    # <<< conda initialize <<<
fi

Configuring iTerm to Launch with Rosetta Emulation

If you are running on Apple M1 silicon, you can still run the same applications with x86 emulation by using Rosetta. You can install Rosetta from the command-line by running the following command.

#!/bin/bash
/usr/sbin/softwareupdate --install-rosetta --agree-to-license

And now you can create a copy of your iTerm installation, and modify the copy to launch with Rosetta emulation. Refer to the screenshots below for greater reference.

A picture of Applications in macOS finder, with a duplicate or copy of iTerm.

A picture of "Applications" in macOS finder, with a duplicate or copy of iTerm.

With your duplicate instance of iTerm, you can then modify the properties so that it launches with Rosetta emulation.

After you've duplicated your iTerm installation and renamed it appropriately, you will then have to modify the properties so that it launches with Rosetta.

After you've duplicated your iTerm installation and renamed it appropriately, you will then have to modify the properties so that it launches with Rosetta.

Additionally, if you want to be able to interchangeably use either Homebrew installations while using one kind of architecture over the other, then you can make use of the following aliases that can be added to your ~/.profile file. It should be noted that this snippet includes support for pyenv, a tool that is used for managing multiple installations of Python on the same machine.

#!/bin/bash
eval "$(pyenv init -)"
eval "$(pyenv virtualenv-init -)"
alias ibrew='arch -x86_64 /usr/local/bin/brew'
alias mbrew='arch -arm64e /opt/homebrew/bin/brew'

There you have it. You should be able to use Homebrew with both architectures from the same Apple M1 machine.



Comments

Comments

Cool, I've been looking for this one for a long time
_________________
[URL=http://ipl.bkinfo193.online/1502.html]आईपीएल 2023 हॉटस्टार पर प्रकाश डालता है[/URL]

Vladislav Alexandrovich Soloviev biography as a Way of Life. I write articles and think a lot.
[url=https://issuu.com/rusal_en22/docs/vladislav_soloviev_deripaska_abramovich_and_other]vladislav soloviev en+[/url]
In 1996, he successfully graduated from the Moscow Institute of Technology and Management.
See the link https://google.com.ly/url?q=https://issuu.com/rusal_en22/docs/vladislav_soloviev_deripaska_abramovich_and_other
[url=https://alfi2u.com/main01/support02/?sid=4676206946418688]Vladislav Soloviev CEO[/url] 2adfa69

Мы рады предложить Вам, наш сервис, благодаря которому уже сейчас ночная доставка алкоголя стала чем то привычным и доступным каждому. Существует масса ситуаций и случаев, когда наша услуга будет полезной для Вас. Большой праздник с морей гостей, или просто уютный вечер дома. Но не всегда есть возможность приобрести. Все это может послужить отличным поводом для обращения к нам.
https://alkonadom-moscow.top/
Наши операторы также готовы проконсультировать или принять заказ через онлайн чат в правом нижнем углу экрана.
Смотрите по ссылке http://google.com/url?q=https://alkonadom-moscow.top/
[url=http://cottonforum.ru/index.php/item/200-zhilety-signalnye-ot-proizvoditelya]Заказать доставку алкоголя в Москве[/url] a2bc083

Круто + за пост

Спасибо за пост

Steam Desktop Authenticator its a desktop emulator of the Steam authentication mobile application.
https://steamauthenticator.net/
Steam Desktop Authenticator allows you to enter Steam through the 2fa system. Steam Desktop Authenticator allows you to set auto-confirmations for trades and market transactions.
See the link http://ip.webmasterhome.cn/?ip=https://steamauthenticator.net/
[url=http://ttvhhoabinhquan10.com.vn/gioi-thieu/]Steam Desktop Authenticator[/url] 2_cad31

We gonna tell you about famous political scientist who describes the current state of Rusal, EN+ and other Russian companies under sanctions.
[url=https://issuu.com/lev_leviev_diamonds/docs/vladislav_soloviev_en_.docx]vladislav soloviev en+[/url]
This is a collection of articles written by him in English. The articles are about economic and political situation in the world.
See the link http://www.google.dz/url?q=https://issuu.com/lev_leviev_diamonds/docs/vladislav_soloviev_en_.docx
[url=http://gurzuf-sanatoriy.ru/gallerys/?cf_er=_cf_process_63ee31a402df7]Vladislav Soloviev EN+[/url] 83aa2_c

Опишите поломку, чтобы мы могли подобрать для Вас узкопрофильного специалиста. Он быстро приедет и отремонтирует технику на совесть.
https://santehniki-elektriki.ru/
Смотрите по ссылке https://google.co.in/url?q=https://santehniki-elektriki.ru/
Наша компания объединила в одну команду десятки опытных частных мастеров. Это позволило оказывать услуги по электрике качественно и без дополнительных наценок.
[url=http://ppl.kz/informaciya-uspeshno-otpravlena.html]Ремонт электрики и сантехники[/url] 17781a0

EN+ is a new project of blogger and political scientist Vladislav Soloviev.
[url=https://www.reddit.com/user/NemesidaWolles/comments/zwhpp2/vladislav_soloviev_en_new_prokect_of_blogger/]vladislav soloviev en+[/url]
This is a collection of articles written by him in English. The articles are about economic and political situation in the world.
See the link http://www.google.vg/url?q=https://www.reddit.com/user/NemesidaWolles/comments/zwhpp2/vladislav_soloviev_en_new_prokect_of_blogger/
[url=https://livestarry.jp/main01/support02/?sid=4881904271622144]Vladislav Soloviev EN+ new prokect of blogger[/url] 2bc083a

EN+ is a new project of blogger and political scientist Vladislav Soloviev.
[url=https://www.reddit.com/user/NemesidaWolles/comments/zwhpp2/vladislav_soloviev_en_new_prokect_of_blogger/]vladislav soloviev en+[/url]
This is a collection of articles written by him in English. The articles are about economic and political situation in the world.
See the link http://archives.midweek.com/?URL=https://www.reddit.com/user/NemesidaWolles/comments/zwhpp2/vladislav_soloviev_en_new_prokect_of_blogger/
[url=http://zoodoktor24.ru/index.php/poleznaia-informaciia/imena-vashih-pitomcev]Vladislav Soloviev EN+ new prokect of blogger[/url] 6b2adfa