Enable multiple users to install software using homebrew

13

7

I installed homebrew using my other user account (which I use during work), but it is impossible to install software from my newly created personal account:

$ brew install unrar
Error: Cannot write to /usr/local/Cellar

A ls -dl /usr/local/Cellar/ shows that the directory is owned by my other user account.

How do I configure homebrew to allow multiple users to install software?

Sridhar Ratnakumar

Posted 2011-05-14T00:59:29.560

Reputation: 4 041

You can take control from the other user by doing sudo chown -R $(whoami) /usr/local – Nathan Lloyd – 2018-08-20T22:14:15.107

Answers

1

In case your account has root / su / sudo access, you can try the following workaround:

su - myother_user_account -c "brew install ..."

sudo alternative:

sudo -u myother_user_account brew install ...

A handy shell alias (for .bashrc/.zshrc/...):

alias brew="sudo -u myother_user_account brew"

Sridhar Ratnakumar

Posted 2011-05-14T00:59:29.560

Reputation: 4 041

1This is not a recommended solution to the multiple-users problem. It requires users to be able to have root access and/or direct access to run commands as another user which kind of defeats the purpose of having user level privileges in the first place. You can break the model for your own use case given you own the box and both accounts, but it would be ill advised for anybody else to use this and your own system usage would be safer for using proper privilege separations. – Caleb – 2015-09-18T09:46:03.560

I don't agree that this is "not recommended". This is a solution that requires the other user to have root / sudo access. And if this does happen in your specific case, I would totally recommend this. I tried other ways of managing Homebrew permissions and it was a nightmare. Never-ending permission denied errors, although I'd swear I did everything as "recommended". – cubuspl42 – 2019-11-18T18:42:06.243

13

set umaskfor each user first. (.basrc or .profile or .bash_profile)

umask 0002 # group write permission

then give write permission for groups via /usr/local recursively:

sudo chmod -R g+w /usr/local/

then change the owner to staff

sudo chgrp -R staff /usr/local

now, each user, who is in staff group can use brew install and other brew related operations... Mostly every user is in that group.

vigo

Posted 2011-05-14T00:59:29.560

Reputation: 291

1I had to do the same for /Library/Caches/Homebrew to make this actually work. And since all my users have Administrator Access enabled I skipped the chgrp – Duvrai – 2014-12-16T16:50:44.297

1

On the homebrew wiki, it mentions that you can install it anywere, try having local installations for each user.

MatthewFord

Posted 2011-05-14T00:59:29.560

Reputation: 131

I don't want that, actually. I want the software to go to a common place irrespective of who installed it. – Sridhar Ratnakumar – 2011-06-22T03:36:16.737

I've tried this and wish I hadn't as you get messed up user permissions – MatthewFord – 2011-07-12T11:36:05.733