Homebrew https://brew.sh/ lets you install and manage packages and applications from the command line on MacOS.
The new Apple Mac M1 is running Apple Silicon technology which is based on ARM processor (aarch64 architecture) rather than Intel processor (x86_64 architecture). This can cause some issues when wanting to run software compiled for x86_64 when a version is not available yet on aarch64.
To work around this, Apple provide Rosetta which provides an emulation layer to execute x86 opcodes under ARM. You can install Rosetta from terminal with
$ /usr/sbin/softwareupdate --install-rosetta --agree-to-license
To make it simpler to switch between ARM and x86 mode copy set up a new terminal profile which will run under Rosetta emulation.
Run terminal, press Apple + , to open Preferences. Click on your favourite profile, e.g. mine is called "a Homebrew".
Click the three dot icon at the bottom and on the popup menu click Duplicate Profile.
Enter a name like "Rosetta Shell" and click on the tab Shell then tick Run command and enter
env /usr/bin/arch -x86_64 /bin/bash --login
Now if you run terminal using your usual profile it will give you a terminal session running in ARM mode.
If you click menu Shell / New Tab then you should see a list of profiles. Click on the Rosetta Shell one you created.
For ARM mode it will go in the default location /opt/homebrew.
For x86 mode it will go in /usr/local.
In the first tab, type
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
It will install x86 brew to /usr/local/bin/brew.
Finally I add some lines to my shell startup profile ~/.bash_profile to detect which mode I am running in and to set the correct path to brew. I also change the prompt so that I get an i when in Intel x86 mode.
if [ "$(sysctl -n sysctl.proc_translated)" = "1" ]; then# run under rosetta 2 with# env /usr/bin/arch -x86_64 /bin/bash --login#local brew_path="/usr/local/homebrew/bin"eval $(/usr/local/bin/brew shellenv)export PS1="i \D{%I:%M %p}:\w $ "else#local brew_path="/opt/homebrew/bin"eval $(/opt/homebrew/bin/brew shellenv)export PS1=" \D{%I:%M %p}:\w $ "fi
However, the full range is available under x86 brew running under the Rosetta x86 emulation.
E.g. $ brew install ruby
No comments:
Post a Comment