MacOS High Sierra安装Homebrew时遇Permission denied @ rb_sysopen错误求助
Hey there, let’s work through this permission error you’re facing with Homebrew. It’s super frustrating when brew doctor says everything’s fine but you still hit roadblocks installing packages like zsh—here are actionable steps to resolve this:
1. Repair Homebrew Directory Permissions
The most common culprit here is incorrect ownership of Homebrew’s core directories. Run this command to take full ownership of all Homebrew-related files and folders:
sudo chown -R $(whoami) $(brew --prefix)/*
This ensures your user account has the access Homebrew needs to write to its directories, which should eliminate the "Permission denied" error for most cases.
2. Upgrade Your Ruby Version
Your system’s default Ruby (2.0.0p648) is quite outdated, and Homebrew relies on Ruby for some internal operations. Let’s install a newer, Homebrew-managed Ruby:
- Install Ruby via Homebrew:
brew install ruby - Add the new Ruby to your shell’s PATH so it takes precedence over the system version. For bash users, run:
For zsh users, replaceecho 'export PATH="/usr/local/opt/ruby/bin:$PATH"' >> ~/.bash_profile source ~/.bash_profile.bash_profilewith.zshrc. - Verify the upgrade with:
You should see a version like 2.7.x or newer.ruby -v
3. Refresh and Clean Up Homebrew
Sometimes cached files or partial updates can cause unexpected errors. Run these commands to reset Homebrew’s state:
brew update --force brew cleanup
After this, try installing zsh again with brew install zsh.
4. Manually Create Missing Directories (If Needed)
If the error message points to a specific missing directory (e.g., /usr/local/var/homebrew), create it manually and set the correct permissions:
sudo mkdir -p /path/to/missing/directory sudo chown -R $(whoami) /path/to/missing/directory
Replace /path/to/missing/directory with the exact path from your error log.
5. Reinstall Homebrew As a Last Resort
If none of the above works, a clean reinstall might fix underlying corruption. First, uninstall Homebrew:
/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/uninstall)"
Then reinstall it using the official script:
/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
内容的提问来源于stack exchange,提问作者noobmaster69

