Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to run the Homebrew installer under Rosetta 2 on M1 Macbook

I'm on the M1 MacBook. This is the error when I try to install Homebrew:

/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)"

Homebrew is not (yet) supported on ARM processors!
Rerun the Homebrew installer under Rosetta 2.
If you really know what you are doing and are prepared for a very broken experience you can use another installation option for installing on ARM:
  https://docs.brew.sh/Installation

So how do I "Rerun the Homebrew installer under Rosetta 2."?

like image 212
Watson Avatar asked Nov 17 '20 20:11

Watson


People also ask

How do I use Rosetta on M1 Mac?

To install Rosetta on Mac M1, just launch an app that requires the emulation to run on M1 Mac and select Install on the Rosetta 2 installation prompt that shows up. Alternatively, you can install Rosetta by running the softwareupdate –install-rosetta –agree-to-license command in Terminal.

Does Homebrew work on M1 Mac?

If you're coming to M1 Mac fresh, without any old projects or profiles, you probably won't notice; Homebrew will work as it always has. But if you're trying to migrate from an Intel Mac you won't be able to just move packages that were once in /usr/local over to /opt/homebrew .

How do I know if Rosetta 2 is installed on Mac M1?

Simply double-click an app built for an Intel-based Mac and then click Install at the dialog prompt that appears on the screen. Enter your username and password to allow the Rosetta 2 installation to proceed, and once installation is complete, Rosetta will be available for any older apps that need it.

How do I install Rosetta 2 on M1 Mac?

Abnormally, macOS doesn't prompt a window to ask you to install Rosetta, you can still install Rosetta 2 on M1 Mac using commands in Terminal. Press Command-Space to open Spotlight Search, then enter Terminal. Click on Terminal to launch the utility. Type the following command: /usr/sbin/softwareupdate --install-rosetta --agree-to-license

How do I run homebrew on Rosetta?

The easiest way to run Homebrew is with Rosetta 2. 1. Duplicate Your Favourite Terminal for Rosetta Find your favourite terminal, right-click to duplicate it, and rename it for easier identification.

Can Rosetta 2 run on the new Apple silicon hardware?

For some quick background, new Apple Silicon Macs run on different architecture, whereas Macs have been running Intel chips for quite some time. Rosetta 2 translates Intel x86 code to ARM so that it can run on the new Apple Silicon hardware. You can read more about the Rosetta 2 translation environment at the Apple developer site gif interested.

How do I open programs in Rosetta mode on a Mac?

Another option is by going into your applications in Finder, select Terminal and press cmd (⌘)+I and check the "Open using Rosetta" option. Sorry if the formatting is off, first time posting a solution. Show activity on this post.


7 Answers

Got an answer from a developer in the Homebrew github https://github.com/Homebrew/brew/issues/9173

arch -x86_64 /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)"

Use this to install packages:

arch -x86_64 brew install <package>

If you have not yet installed Rosetta 2 to emulate Intel CPUs on ARM Macs, you will get the error arch: posix_spawnp: /bin/bash: Bad CPU type in executable. Prompt a Rosetta 2 installation with:

softwareupdate --install-rosetta
like image 200
Watson Avatar answered Oct 22 '22 04:10

Watson


I have two instances of brew installed, the Intel version that runs using Rosetta2 and which installs to /usr/local/bin and the Arm version that runs natively and installs to /opt/homebrew/bin. Now it is all working, I do not have to start iTerm using Rosetta.

I have these aliases to reach the two versions.

ibrew='arch -x86_64 /usr/local/bin/brew'
mbrew='arch -arm64e /opt/homebrew/bin/brew'

I have the native version in my path first:

path=( /opt/homebrew/bin /opt/homebrew/opt /usr/local/bin /usr/bin /bin /usr/sbin /sbin /Library/Apple/usr/bin )

Now I can try mbrew search and mbrew install. If they work, I am good to go with a native program. For example:

mbrew install ag

If brew fails I try building from source, with verbose output, e.g.

mbrew install -sv rust

Be warned, this takes a while and may still fail.

If it still fails, (and mbrew install -sv go results in a segmentation fault for me) I have two choices. Use ibrew search and ibrew install to get the Intel build instead, or examine the verbose output and look for problem dependencies. In some cases an install -s on the dependencies is enough to get the native brew to work.

I must stress that native brew always prints this warning

Warning: You are running macOS on a arm64 CPU architecture.
We do not provide support for this (yet).
Reinstall Homebrew under Rosetta 2 until we support it. 

So proceed at your own discretion.

For completeness, and assuming you have iTerm2, Rosetta2 and the Xcode command line tools installed, I did this to install brew under Rosetta (with credit to all those who have posted on this page before me):

  1. Copy the installed iTerm2.app application to iRosetta2.app
  2. Press command+I to Get Info for iRosetta.app, click Open Using Rosetta2
  3. Run iRosetta2 and use this command from https://brew.sh

Like so

/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)
alias ibrew='arch -x86_64 /usr/local/bin/brew' # put this in ~/.zshrc

And I did this to install native brew, taken from other contributors to Stack Overflow and the Homebrew alternative installation site, using iTerm2 without Open Using Rosetta2

mkdir ~/homebrew
curl -L https://github.com/Homebrew/brew/tarball/master | tar xz --strip 1 -C homebrew
sudo mv ~/sudo mv homebrew /opt
mbrew='arch -arm64e /opt/homebrew/bin/brew' # for .zshrc
export PATH="/opt/homebrew/bin:/opt/homebrew/opt:$PATH" # also for .zshrc

Edit

Time has passed and I have changed the architecture to arm64e following Fernando García Redondo observation. Now the warning about Arm architecture not supported has gone and Rust and Go install with problems and without compiling from source. I assume the good people at Homebrew have been working hard over Christmas. Thanks!

Edit Feb 21

The Homebrew team have announced that they support Apple silicon. So I wondered if I could delete my aliases and just use brew to install for Apple silicon. The short answer is no! if you run brew from /usr/local without the arch -x86_64, it complains that /usr/local is reserved as the Intel default prefix and using /opt/homebrew is required. So I will retain my two aliases and try mbrew first and only use ibrew if the native brew fails.

like image 40
Nigel Davies Avatar answered Oct 22 '22 05:10

Nigel Davies


Another option is by going into your applications in Finder, select Terminal and press +I and check the "Open using Rosetta" option.

Sorry if the formatting is off, first time posting a solution.

like image 53
Alan Weng Avatar answered Oct 22 '22 04:10

Alan Weng


The easiest way to run Homebrew is with Rosetta 2.

1. Duplicate Your Favourite Terminal for Rosetta

Find your favourite terminal, right-click to duplicate it, and rename it for easier identification. In this example, I'm using the default Terminal app on Big Sur 11.2.1.

duplicate-terminal-right-click-option

duplicate terminal rosetta m1 homebrew

Right-click the Terminal Rosetta and go to Get Info to check the Open using Rosetta option.

enter image description here

2. Install Homebrew

Open the rosetta terminal and run the following command:

/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"

Running this command will ask you for the password, and then it will provide you with the information of what all it will install and which new directories it will create.

3. Using Homebrew

Once HomeBrew is installed, you can start using it to install your required packages into the M1 Mac.

Run the following command to get brew help:

brew help

To install a package, you can run the following command:

brew install packagename

That’s all about installing and getting started with Homebrew on Apple M1 Macs.

EDIT: Thanks all! Upvote to help other devs! Homebrew 3.0.0 now officially supports Apple Silicon (https://brew.sh/2021/02/05/homebrew-3.0.0/)

like image 22
Khairul Avatar answered Oct 22 '22 05:10

Khairul


After I installed Rosetta, I added an alias so I can use brew install <package> as I would normally.

alias brew='arch -x86_64 brew'

I agree with everyone else in that you need to add the arch -x86_64 in front of the original command so thought to include that alias to help anyone finding this thread in the future

like image 13
Echen Avatar answered Oct 22 '22 05:10

Echen


arch -x86_64 /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)" worked on my new M1 Mac

like image 8
sudha Avatar answered Oct 22 '22 04:10

sudha


Do below

  • /usr/sbin/softwareupdate --install-rosetta --agree-to-license
  • arch -x86_64 /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)"
  • alias brew='arch -x86_64 brew'
  • brew install azure-cli

now try az login. you are good to go

like image 6
shashank shekhar Avatar answered Oct 22 '22 06:10

shashank shekhar