LoveDuckie

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

Updated 3 years ago
5 Minute(s) to read
Posted 3 years ago Updated 3 years ago 5 Minute(s) to read 295 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

Gravatar for Michaeldiple
Michaeldiple
Posted Nov 17, 2022, 10:28 AM (2 years ago)

Luc Shelton &raquo; Homebrew and Anaconda: Configuring for Apple M1 and Intel Silicon
-
https://politiko.ua/blogpost161152
https://community.clover.com/users/30564/kazik.html
https://regforum.ru/forum/members/208765/#about
https://photobuildings.com/author/10040/
https://git.disroot.org/irishman
https://torgi.gov.ru/forum/user/profile/1700499.page
https://www.anime-planet.com/users/tor777
https://www.sailnet.com/members/irishman7.551055/#about
https://www.tipga.com/about/stog777
https://www.diggerslist.com/irishman/about

Thanks !

VALUE FLIGHTS - HOTELS - TOURS TO THE WORLD
https://heureuxvoyageur.com/
EXCLUSIVE DEALS
Plan your travels from exclusive travel websites.
EASY BOOKING
Compare all the top travel booking websites.
BEST PRICE
Find our lowest of worldwide travels price.
HUGE SAVINGS
Booking travels with no booking fee and hidden cost

Gravatar for Michaeldiple
Michaeldiple
Posted Nov 17, 2022, 9:28 AM (2 years ago)

Luc Shelton &raquo; Homebrew and Anaconda: Configuring for Apple M1 and Intel Silicon
-
https://www.mobygames.com/user/sheet/userSheetId,942482/
https://trabajo.merca20.com/author/irishman/
https://www.imdb.com/user/ur156874916/
https://community.sagecrm.com/members/y5eey5etytyr/default.aspx
https://seedandspark.com/user/irishgame
https://wacowla.com/chineseclassifieds/author/irishman/
http://foxsheets.com/UserProfile/tabid/57/userId/104318/Default.aspx
https://www.divephotoguide.com/user/irishman
https://academy.webvent.tv/profile/416269/0
https://www.theloop.com.au/project/irishman/portfolio/top-australian-online-casino/454324

Thanks !

Gravatar for Michaeldiple
Michaeldiple
Posted Nov 17, 2022, 9:10 AM (2 years ago)

Luc Shelton &raquo; Homebrew and Anaconda: Configuring for Apple M1 and Intel Silicon
-
http://msnho.com/blog/online-casino-real-money
https://www.ijimai.org/journal/user/55174
https://www.vinow.com/wwwtalk/profile/irishman5/
https://www.electronicsforu.com/author/irishman
https://yarabook.com/1662923693976592_611198
https://mkt.marketinginasia.com/profile/irishman5
https://www.emoneyspace.com/tor778
https://www.sbnation.com/users/irishsport
https://wecanchat.mn.co/members/12756716
http://auto-file.org/member.php?action=profile&uid=474528

Thanks !

Gravatar for Michaeldiple
Michaeldiple
Posted Nov 17, 2022, 8:04 AM (2 years ago)

Luc Shelton &raquo; Homebrew and Anaconda: Configuring for Apple M1 and Intel Silicon
-
https://www.sunnyvalechristian.school/profile/stog77781/profile
https://www.carhubsales.com.au/user/profile/762186
https://jobhop.co.uk/blog/175593/mobile-no-deposit-casinos-with-money-withdrawal
https://forum.iobroker.net/user/rich6/
https://arthive.com/ru/users/161969
https://www.gog.com/u/tor7778
https://band.us/band/88955316
https://sidney.instructure.com/courses/19859/pages/top-onlain-kazino
http://blogforum.kasipkor.kz/en/community/profile/karen/
https://ru.gravatar.com/topvyigrysh

Thanks !

Gravatar for Michaeldiple
Michaeldiple
Posted Nov 17, 2022, 7:50 AM (2 years ago)

Luc Shelton &raquo; Homebrew and Anaconda: Configuring for Apple M1 and Intel Silicon
-
https://www.fbtb.net/author/topirishman/
https://employbahamians.com/author/irishman7/
https://www.emdr-mn.com/author/irishman/
https://projectnursery.com/author/irishman/
https://www.inkitt.com/irishman5
https://naijamp3s.com/profile/irishman
https://forum.bigant.com/member.php?action=profile&uid=489823
https://www.diyrenovationsonline.com.au/author/topirishman/
https://oilpatchsurplus.com/author/irishman/
https://www.wellarmed.us/forums/users/topirishman/

Thanks !

«Стройтех42» — одна из самых перспективных компаний на рынке малоэтажного строительства за счет качества выполняемых работ и строгого соблюдения сроков сдачи.
<a href=https://rpgcraft.ru/index.php/community/profile/jessikadoty565/>строительство домов в новокузнецке</a>
В нашей компании вы можете оформить кредит на строительство дома под ключ на выгодных условиях. В банк ехать не нужно. Принимаем материнский капитал.
<a href=http://www.gisthai.org/webboard/Question.asp?GID=103>Выполняем полный цикл работ под ключ</a> fa69e31

Получайте деньги легко зарабатвая на смартфоне , решая легкие задания!

У всех желающих есть доступная возможность создать, как дополнительный заработок, так и удаленную работу!
С Profittask Вы сможете заработать до 1000 руб. каждый день, выполняя несложные задания, находясь в своей квартире с доступом в интернет!

Чтобы создать легкий интернет заработок, вам необходимо всего лишь <b><a href=https://profittask.com/?from=4102/>скачать бесплатную программу</a></b> и зарабатывать уже сейчас!
Поверьте это легко, просто и доступно для каждого - без вложений и специальных навыков действуйте у вас получится!
<a href=https://profittask.com/?from=4102>заработок в интернете официальный сайт</a>

Расценки на работы в деревянных домах из бруса и срубов из бревна. Мы выполняем весь комплекс отделочных и инженерных работ под ключ в Москве и области. Профессионально, качественно и с гарантией.
<a href=https://otdelka-derevyannogo-doma.ru/>отделка деревянного дома</a>
Смотрите по ссылке - http://ccasayourworld.com/?URL=https://otdelka-derevyannogo-doma.ru/
Профессионально выполняем отделку деревянных домов под ключ более 12 лет. Работаем со всеми типами деревянных поверхностей и используем экологичные материалы.
<a href=https://mediastog.ru/news/Rus/vse-semi-s-detmi-poluchat-po-10000-rublej.html>Покраска, герметизация и отделка деревянных домов</a> 2_ba71f

Attractive component of content. I simply stumbled upon your weblog and in accession capital to say that I acquire in fact loved account your blog posts.
Anyway I will be subscribing for your augment and even I
success you access persistently quickly.