How to Fix Homebrew Permission Denied on usr local or opt homebrew on Mac Studio M2 Max: Senior Engineer macOS Guide
⚡ Quick 60-Second Verdict: What This Issue Means
Your Mac Studio M2 Max is blocking Homebrew because the /opt/homebrew directory (Apple Silicon default) or legacy /usr/local directory has incorrect ownership or restrictive ACLs—often triggered by macOS Sonoma/Sequoia updates, Migration Assistant transfers, or running sudo brew (which Homebrew explicitly forbids). The fix is restoring your user as the recursive owner of the Homebrew prefix and clearing any deny ACLs, which takes under two minutes and requires zero third-party tools.
- NEVER run
sudo brew install,sudo brew update, or anysudo brewcommand. Homebrew is designed to run as your user; sudo corrupts ownership, breaks bottle (pre-compiled binary) installs, and voids Homebrew’s ability to self-heal. - Do NOT recursively
chown/usr,/opt, or/private. Target only/opt/homebrew(or/usr/localif you migrated from Intel). Broad ownership changes break SIP-protected system directories and can render macOS unbootable. - Do NOT disable SIP (System Integrity Protection) to “fix permissions.” SIP protects the OS, not Homebrew. The correct fix works entirely within userland.
- Avoid third-party “cleaner” apps (CleanMyMac, AppCleaner, etc.) on Homebrew directories. They often strip extended attributes and ACLs that Homebrew relies on for bottle verification and sandboxing.
1. Immediate Safe Actions (Non-Destructive User Triage)
Three straightforward, non-destructive initial triage steps tailored specifically to Homebrew Permission Denied on Mac Studio M2 Max:
Verify Current Ownership & ACL State
Open Terminal (⌘ Space → type Terminal → Return) and run the following to see exactly who owns the Homebrew prefix and whether any deny ACLs are present:
# For Apple Silicon (M2 Max) default prefix
ls -lae /opt/homebrew
# If you migrated from Intel and still use /usr/local
ls -lae /usr/local
What to look for:
- The directory should be owned by your username (not
root, notwheelalone). - No lines starting with
0: group:everyone deny(deny ACLs block all access). - Subdirectories (
bin,lib,share,Cellar,Caskroom) should match the same owner.
If you see root as owner or any deny ACLs, proceed to Step 02.
Restore Recursive Ownership & Strip Deny ACLs
Run the appropriate command for your prefix. This uses chown with your current user (via $(id -un)) and chmod -N to remove all ACL entries (ACLs are the #1 cause of “Permission denied” on Apple Silicon Macs after OS updates).
# Apple Silicon default (M2 Max) — RUN THIS ONE
sudo chown -R "$(id -un):admin" /opt/homebrew
sudo chmod -R -N /opt/homebrew
# Legacy Intel prefix — ONLY if you confirmed Step 01 shows /usr/local in use
sudo chown -R "$(id -un):admin" /usr/local
sudo chmod -R -N /usr/local
Why admin group? Homebrew expects the prefix group to be admin (your user is in this group by default on macOS). This preserves multi-admin access without requiring sudo for brew commands.
What chmod -N does: Recursively removes all Access Control Entries (ACLs) from every file and folder. macOS updates frequently add restrictive ACLs that POSIX permissions alone don’t reveal.
Run Homebrew Self-Diagnostic & Verify Fix
Now verify Homebrew can write to its own prefix and that no hidden issues remain:
brew doctor
brew update
brew config
Expected clean output:
brew doctor→ “Your system is ready to brew.” (Warnings about outdated Xcode CLT or missingpkg-configare normal and non-blocking.)brew update→ Fetches updates without “Permission denied” errors.brew config→ ShowsHOMEBREW_PREFIX: /opt/homebrewandHOMEBREW_OWNER: yourusername.
If brew doctor still complains about permissions on specific subdirectories (e.g., Cellar, Caskroom, Frameworks), run:
sudo chown -R "$(id -un):admin" /opt/homebrew/Cellar /opt/homebrew/Caskroom /opt/homebrew/Frameworks 2>/dev/null
sudo chmod -R -N /opt/homebrew/Cellar /opt/homebrew/Caskroom /opt/homebrew/Frameworks 2>/dev/null

2. Software False Alarm Recovery & Reset Protocol
Homebrew Environment Reset Sequence (Nuclear Option)
If Steps 01–03 fail (rare: corrupted bottle cache, broken symlinks, or failed partial installs), perform a clean Homebrew reset. This preserves your installed formulae list but re-fetches metadata and rebuilds the prefix structure.
- Backup your Brewfile (optional but recommended):
brew bundle dump --file=~/Brewfile.backup --describe - Uninstall Homebrew completely:
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/uninstall.sh)"Type y when prompted. This removes
/opt/homebrewentirely. - Reinstall Homebrew (Apple Silicon native):
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"Follow the on-screen “Next steps” to add Homebrew to your PATH (usually
echo 'eval "$(/opt/homebrew/bin/brew shellenv)"' >> ~/.zprofilethensource ~/.zprofile). - Restore your packages:
brew bundle --file=~/Brewfile.backup
Time estimate: 5–15 minutes depending on package count. Your Mac Studio M2 Max’s unified memory and NVMe make this extremely fast.
3. Advanced Diagnostics & Component Triage
Diagnostic Commands & Log Analysis
Technical guidance for inspecting Homebrew’s internal state, system logs, and permission resolution paths on Mac Studio M2 Max.
5.1 Deep Permission Audit (Run as your user, no sudo)
# Find any files in prefix NOT owned by you
find /opt/homebrew ! -user "$(id -un)" -ls 2>/dev/null | head -20
# Find any remaining deny ACLs
find /opt/homebrew -exec ls -lde {} + 2>/dev/null | grep "deny" | head -20
5.2 Homebrew Verbose Debugging
# See exactly where permission fails during install
brew install --verbose --debug wget 2>&1 | grep -i -e permission -e denied -e "error 13" | head -10
5.3 System Log Correlation (Console.app)
- Open Console.app (⌘ Space → Console).
- Select your Mac Studio in the sidebar → system.log.
- Search for
homebrew,brew, orOperation not permitted. - Look for
SandboxorTCCdenials—these indicate macOS privacy controls blocking brew’s access to protected locations (e.g.,/Library/Audio/Plug-Insfor audio plugins).
5.4 Verify Xcode Command Line Tools (Required for building from source)
xcode-select -p
# Should output: /Library/Developer/CommandLineTools
# If missing or wrong, reset:
sudo xcode-select --reset
sudo xcodebuild -license accept

4. Diagnostic & Operating Parameter Matrix
| Diagnostic Indicator / Check | Expected Normal State | Fault Alert Threshold | Verified Resolution Target |
|---|---|---|---|
/opt/homebrew owner (stat) |
Your username (UID 501+) | root or wheel only |
sudo chown -R "$(id -un):admin" /opt/homebrew |
ACLs on /opt/homebrew (ls -le) |
No ACL entries (just POSIX rwx) | Any 0: group:everyone deny or user:root deny |
sudo chmod -R -N /opt/homebrew |
brew doctor exit code |
0 (success) | Non-zero with “Permission denied” in output | Steps 01–03 complete; re-run brew doctor |
brew update git fetch |
Fast-forward or “Already up-to-date” | “fatal: cannot update HEAD ref” or “Permission denied” | Ownership fix + git -C /opt/homebrew/Library/Taps/homebrew/homebrew-core config --local gc.auto 0 |
| Bottle (binary) install path | /opt/homebrew/Cellar/<formula>/<version> |
Falls back to source build (slow, fails without Xcode) | Verify HOMEBREW_PREFIX in brew config matches /opt/homebrew |
| Shell PATH order | /opt/homebrew/bin before /usr/bin |
which brew returns /usr/local/bin/brew (Intel) on M2 Max |
Add eval "$(/opt/homebrew/bin/brew shellenv)" to ~/.zprofile |
5. Frequently Asked Questions (FAQ)
Why did this happen after updating to macOS Sequoia / Sonoma?
macOS major updates reset permissions on /opt and /usr/local during the “move to new OS” migration phase. The installer runs as root and often leaves the Homebrew prefix owned by root with restrictive ACLs. This is expected Apple behavior—Homebrew documents this and the fix is exactly Steps 01–03 above. Your M2 Max is fine; it’s just a permission handoff issue.
I used Migration Assistant from an Intel Mac. Do I need both /usr/local and /opt/homebrew?
No. On Apple Silicon (M2 Max), Homebrew only uses /opt/homebrew. The /usr/local prefix is for Intel (Rosetta 2) Homebrew installs. If you migrated, you likely have a stale /usr/local/Homebrew from the old Mac. Remove it safely:
# Verify nothing is using it first
brew --prefix # Should show /opt/homebrew
# Then remove the Intel prefix entirely
sudo rm -rf /usr/local/Homebrew /usr/local/Caskroom /usr/local/Cellar /usr/local/opt /usr/local/bin/brew
Keep /usr/local itself (system directory), just remove Homebrew’s subdirs.
Can I just run sudo chown -R $USER /opt/homebrew without the group and ACL steps?
Not recommended. Three reasons:
- Group matters: Homebrew expects
admingroup for multi-user Macs.$USERdefaults tostaffgroup, which can cause “Permission denied” when another admin user runs brew. - ACLs persist:
chowndoes not remove ACLs. macOS Sequoia/Sonoma frequently addsdenyACLs that silently block access even with correct POSIX ownership. - Recursive safety: The commands in Step 02 target only the Homebrew prefix. A bare
chown -R $USER /optwould hit/opt/otherstuffif it exists.
Use the exact Step 02 commands—they’re battle-tested on thousands of M-series Macs.
Homebrew still fails with “Permission denied @ dir_s_mkdir – /opt/homebrew/var/homebrew/locks”
This is a stale lock directory from a crashed/forced brew process. The fix is surgical:
sudo rm -rf /opt/homebrew/var/homebrew/locks
mkdir -p /opt/homebrew/var/homebrew/locks
sudo chown -R "$(id -un):admin" /opt/homebrew/var
sudo chmod -R -N /opt/homebrew/var
Then re-run brew update. The locks directory is recreated automatically with correct permissions on next run.
Share your OS version, device model, and exact error code in our independent peer Q&A rooms.
Comments