I know this is a frequently asked question, but I am really struggling.
I have recently tried to install MySQL with Homebrew on my Mac OS El-Capitan. However, I have encountered some problems with it and I want to reinstall it. Yet whenever I try doing that it gives me:
Error: Permission denied @ rb_sysopen - /usr/local/var/homebrew/locks/mysql.formula.lock
I tried to bypass this error by simply sorting the named files out manually in the root account, but there were way too many files.
So I tried uninstalling it with root, but it gave me this error:
Error: Running Homebrew as root is extremely dangerous and no longer supported.
As Homebrew does not drop privileges on installation you would be giving all
build scripts full access to your system.
I looked at many articles, including this link! Many of them suggested that I chown the /usr/local folder directly to my own user account with root, so I can run brew without any permission problems, but it is too dangerous.
I tried to run:
sudo chown root /usr/local/bin/brew
But this did not work as well.
Is there any ways I can bypass this error, and run brew as root?
Many of them suggested that I chown the /usr/local folder directly to my own user account with root, so I can run brew without any permission problems, but it is too dangerous.
chown
ing all of /usr/local/
is probably a bad idea because it's not entirely under Homebrew's control. But just /usr/local/var/homebrew/locks/mysql.formula.lock
should be ok.
chown $USER /usr/local/var/homebrew/locks/mysql.formula.lock
And follow the advice of brew doctor
.
tried to run:
sudo chown root /usr/local/bin/brew
But this did not work as well.
All this accomplished was to make the file /usr/local/bin/brew
owned by root. It doesn't make it run as root. You should change it back to being owned by your user else you won't be able to upgrade brew.
To make it run as root you'd use setuid. Do not do this. It's inherently dangerous, and doubly so with your current understanding of permissions. Nothing personal, permissions take a while to get used to and appreciate.
Homebrew does not run as root to limit the damage possible by a malicious package or a simple mistake. By running as your user it can only damage what is accessible to your user. This walls off important things like system files. This is the purpose of the Unix permission system: to limit how much damage is possible. If you run brew
as root all bets are off.
Furthermore, if /usr/local/var/homebrew/locks/mysql.formula.lock
is owned by root that means MySQL ran as root. If you run MySQL as root and it is compromised your whole system is compromised. If you run MySQL as your user or a special limited mysql user, only your user files or mysql's own files can be compromised. Run it as proscribed by homebrew.
It's very much worth it to learn to run with as few permissions as possible.