How to fix permission issues on Homebrew in OS X El Capitan?
You upgraded to Mac OS X El Capitan and cannot use Homebrew anymore. As a developer myself who uses homebrew pretty regularly, I can totally understand the feeling.
The reason these permission issues are arising is a result of Apple's new changes to Mac OS X 10.11 El Capitan called SIP which stands for System Integrity Protector. More about SIP towards the end of this article.
Here is how you can fix the permission issues with Homebrew in Mac OS X El Capitan:
If you had created the /usr/local directory already, then run this command in terminal:
sudo chown $(whoami):admin /usr/local && sudo chown -R $(whoami):admin /usr/local
And you should be all set.
Update - I have created this new guide titled - How to install Homebrew in Mac OS X El Capitan?
However, If you are doing a fresh install or cannot create /usr/local directory anymore, then follow these steps:
Step 1: Reboot into Recovery mode (Hold Cmd+R on boot) & access the Terminal. (Yes, you will have to go into recovery mode as that is the only way to disable SIP as of now.)
Step 2: In the terminal, run the following command:
Step 3: Reboot back into OS X El Capitan
Step 4: Once Mac restarts, Open your Terminal and run the following command:
sudo mkdir /usr/local && sudo chflags norestricted /usr/local && sudo chown $(whoami):admin /usr/local && sudo chown -R $(whoami):admin /usr/local
Step 5: After you have done above, you will need to reboot back into Recovery Mode once more & open the Terminal and type the following command:
Step 6: Now, reboot back into OS X
Step 7: You will now be able to write to the /usr/local directory and proceed with installing Homebrew as you would regularly.
You need not worry about any of the steps of issues that I outlined above if you have not installed Homebrew in /usr/local or another system-protected directory.
More about SIP - System Integrity Protector:
With SIP, you can no longer write to system directories like /usr , /System and /bin even though you have root permissions or you you have logged in as the user root.
According to the Apple documentation, the /usr/local directory will have the root:wheel restricted permissions like before with every forthcoming OS X update.
The Homebrew team has acknowledged this issue and they will soon be adding a brew doctor check that will warn you about any of these issues in the near future.
Thanks for reading and please let me know in the comments section, if this helped you.