Error: Permission denied @ apply2files - /usr/local/Cellar/
0 reputation · 26 Mar 2024, 15:28 UTC
0 reputation · 26 Mar 2024, 15:28 UTC
Goal: Allow Homebrew to write to /usr/local/Cellar without encountering the 'Permission denied @ apply2files' error while preserving system integrity and avoiding architecture‑specific conflicts.
Constraints: Changing ownership with sudo chown can sidestep system protections and may interfere with other software that expects the original permissions; moving Homebrew to the Apple Silicon‑specific /opt/homebrew prefix avoids the error but requires reinstalling existing formulas and may lead to duplicate installations if both Intel and Apple Silicon bins are kept; retaining the /usr/local prefix on Intel Macs raises uncertainty about future migration to Apple Silicon and potential permission regressions.
Is it safer to adjust ownership of /usr/local/Cellar or to migrate Homebrew to /opt/homebrew on Intel Macs? What are the long‑term implications for future Apple Silicon migration if the Intel prefix is retained? How can users verify that permission adjustments do not violate system integrity protections or cause conflicts with other software?
For most Intel‑Mac users the safest, simplest fix is to correct the ownership of the /usr/local/Cellar directory so that the current user has write access. Changing ownership of the whole /usr/local tree is unnecessary and can interfere with other installers that expect root ownership.
Migrating Homebrew to the Apple‑Silicon prefix /opt/homebrew on an Intel Mac is possible but creates a second, independent Homebrew instance. It is only advisable if you plan to keep a dual‑architecture setup or want to experiment with the new prefix. In the long run, the Intel installation will remain dormant on Apple‑Silicon machines, so keeping the /usr/local prefix is perfectly fine for future migration.
/usr/local is outside System Integrity Protection./opt/homebrew without affecting the existing /usr/local installation.Check current ownership:
ls -ld /usr/local /usr/local/Cellar
If the owner is root or another user, change it to your account:
sudo chown -R $(whoami) /usr/local/Cellar
This command preserves the parent /usr/local permissions and only affects the Cellar where Homebrew writes.
Verify permissions are now writable by the user:
ls -ld /usr/local/Cellar
Run Homebrew’s health check:
brew doctor
A clean output indicates the change is safe.
Ensure other tools still work (e.g., Xcode command‑line tools):
xcode-select -p
Any failure here suggests an unintended side effect.
To migrate, install a fresh Homebrew instance with the desired prefix and reinstall formulas:
env HOMEBREW_PREFIX=/opt/homebrew /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
brew install $(brew list)
Keep in mind this duplicates disk usage and requires maintaining two separate caches.
/usr/local Homebrew remains untouched on Apple‑Silicon Macs; Homebrew will automatically use /opt/homebrew instead.PATH order is ambiguous./usr/local or /opt/homebrew) keeps the system simpler and reduces the risk of stale or conflicting binaries.ls -ld /usr/local/Cellar shows ownership as your user and mode drwxr-xr-x (or drwxrwxr-x if you added group write).brew doctor reports no insecure directory warnings.gcc, make, and xcode-select run without permission errors./usr/local/Cellar to your user./opt/homebrew is optional and creates a separate Homebrew instance.PATH and HOMEBREW_PREFIX environment will change.brew doctor and system tool checks.Use comments to ask for clarification. Post a solution as an answer.
32,275 reputation · 26 Mar 2024, 21:49 UTC
When fixing the Permission denied @ apply2files error, limit ownership changes to Homebrew‑managed directories only: /usr/local/Cellar, /usr/local/Homebrew, and /usr/local/opt (if you keep linked kegs there). Changing the whole /usr/local tree can affect unrelated software that expects root ownership.
brew doctorAfter adjusting ownership, run:
brew --prefix
ls -ld $(brew --prefix)Cellar
The prefix should point to /usr/local and the directory listing show your user as owner. Then test a typical install:
brew install wget
brew list --versions wget
which wget
If which wget resolves to /usr/local/bin/wget and brew doctor reports no warnings, the change is safe and does not interfere with System Integrity Protection or other tools.