Keywords: Apple Silicon | Homebrew | ARM Architecture | Rosetta2 | Package Management
Abstract: This technical article provides a comprehensive analysis of the 'Cannot install in Homebrew on ARM processor in Intel default prefix' error encountered when using Homebrew on Apple M1 chip Macs. It offers a complete solution starting from error cause analysis, through step-by-step guidance for installing Rosetta2 emulator, correctly installing Homebrew ARM version, to using arch commands for managing software packages across different architectures. With clear code examples and in-depth technical analysis, users can thoroughly resolve this compatibility issue.
Problem Background and Error Analysis
With the widespread adoption of Apple Silicon chips, many developers face software compatibility issues when migrating to M1 series processors. Homebrew, as a popular package manager on macOS, requires special configuration to function properly in ARM architecture environments. When users execute the brew install openjdk@11 command on Apple Silicon devices, the system throws the error message: Error: Cannot install in Homebrew on ARM processor in Intel default prefix (/usr/local)!.
The root cause of this error lies in Homebrew's architecture detection mechanism. While Apple Silicon Macs natively support ARM64 architecture, the system provides Rosetta2 translation layer for running x86_64 applications. Homebrew's default installation path /usr/local is designed for Intel architecture, while ARM architecture requires a dedicated installation path /opt/homebrew.
Solution: Complete Installation Process
To completely resolve this issue, follow these steps in the correct order:
Step 1: Install Rosetta2 Emulator
Rosetta2 is Apple's dynamic binary translation tool that allows x86_64 applications to run on ARM architecture. Before installing Homebrew, Rosetta2 must be installed first:
/usr/sbin/softwareupdate --install-rosetta --agree-to-license
This command automatically downloads and installs Rosetta2 without user interaction. Once installed, the system gains the capability to run Intel architecture applications.
Step 2: Install Homebrew ARM Version
Use the following command to install Homebrew specifically optimized for ARM architecture:
arch -x86_64 /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)"
The key here is the arch -x86_64 prefix, which instructs the system to use Rosetta2 translation layer to execute the subsequent bash script. This ensures the installation process occurs in a compatible Intel emulation environment while correctly installing Homebrew to the ARM-specific /opt/homebrew path.
Step 3: Use Correct Brew Commands
After installation, all brew commands require the architecture prefix:
arch -x86_64 brew install <package>
For example, to install openjdk@11:
arch -x86_64 brew install openjdk@11
In-depth Technical Principles
Understanding the technical principles behind this solution is crucial for avoiding similar issues in the future.
Architecture Isolation Mechanism
Homebrew employs a strict architecture isolation strategy. On Apple Silicon devices, the system maintains two separate Homebrew instances:
- Intel architecture version: Located at
/usr/local, running through Rosetta2 - ARM architecture version: Located at
/opt/homebrew, running natively
This design avoids architecture conflicts, ensuring each software package runs in the correct environment. When detecting a processor architecture mismatch with the installation path, Homebrew proactively blocks installation to prevent potential compatibility issues.
Environment Variable Configuration
To simplify usage, configure shell environment variables. Execute the following command to add Homebrew's ARM version to PATH:
eval "$(/opt/homebrew/bin/brew shellenv)"
This command automatically sets necessary environment variables, including HOMEBREW_PREFIX, PATH, etc., enabling direct use of brew command without specifying the full path each time.
Best Practices and Troubleshooting
Dual Architecture Management Strategy
For scenarios requiring management of both Intel and ARM architecture software packages, adopt the following strategy:
# Create alias for Intel architecture packages
alias brew86='arch -x86_64 /usr/local/bin/brew'
# Create alias for ARM architecture packages
alias brewa='/opt/homebrew/bin/brew'
This alias mechanism makes architecture management clearer, avoiding command confusion.
Common Issue Troubleshooting
If issues persist, execute the following diagnostic commands:
# Check Homebrew configuration
brew config
# Diagnose potential issues
brew doctor
# Verify architecture
uname -m
The brew doctor command is particularly useful, as it detects configuration issues and provides repair suggestions.
Migrating Existing Configuration
For users migrating from Intel Macs to Apple Silicon, Homebrew provides configuration migration tools:
# Export currently installed package list
brew bundle dump
# Restore installation in new environment
brew bundle install
This process creates a Brewfile that records all installed packages, facilitating quick development environment restoration in new environments.
Conclusion
The key to successfully using Homebrew on Apple Silicon devices lies in understanding architecture isolation principles and following the correct installation process. By installing Rosetta2, using architecture prefixes for command execution, and properly configuring environment variables, developers can fully leverage M1 chip performance advantages while maintaining good software compatibility. As the ecosystem matures, Homebrew is expected to provide more seamless cross-architecture support, but currently following the steps described in this article remains the most reliable solution.