Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I run brew as root?

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?

like image 837
Aarony Jamesys Avatar asked Nov 14 '25 20:11

Aarony Jamesys


1 Answers

Using brew as root is a bad idea due security reasons. Instead you can change the brew file ownership to the current logged in user. Type this single command:

sudo chown $USER /usr/local/bin/brew
like image 131
Emeka Augustine Avatar answered Nov 17 '25 10:11

Emeka Augustine