Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Homebrew multi user setup

I was trying to fix my Homebrew installation for multiple users and found a guide on strug.de, which aims to solve exactly this issue.

I created a brew user group, added both of my users in that group and ran this to adjust the permissions:

sudo chgrp -R brew /usr/local
sudo chmod -R g+w /usr/local
sudo chgrp -R brew /Library/Caches/Homebrew
sudo chmod -R g+w /Library/Caches/Homebrew
sudo chgrp -R brew /opt/homebrew-cask
sudo chmod -R g+w /opt/homebrew-cask

Let's assume I did this while logged into user account A. A few days later I'm logged into user account B and try to install Dropbox via Cask. That works like a charm, since we fixed the permissions earlier so the brew group is allowed to write in those folders as well.

Now another few days later, I am back logged into account A and want to get rid of Dropbox. I run the following command but stuck with the permission error:

$ brew cask install dropbox --force
==> Downloading https://www.dropbox.com/download?plat=mac&full=1
Already downloaded: /Library/Caches/Homebrew/dropbox-latest
==> Symlinking App 'Dropbox.app' to '/Users/friedmann/Applications/Dropbox.app'
Error: Permission denied - /opt/homebrew-cask/Caskroom/dropbox/.metadata/latest/20150217070443.598

  Most likely, this means you have an outdated version of homebrew-cask. Please run:

      brew update && brew upgrade brew-cask && brew cleanup && brew cask cleanup

  If this doesn’t fix the problem, please report this bug:

      https://github.com/caskroom/homebrew-cask/issues

/System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/fileutils.rb:245:in `mkdir'
[...]

To fix this for the user B, I have to run the chgrp's and chmod's (as stated above) again. However this workaround is not really appreciated, since I don't want to "randomly" run all the commands whenever I switch back and forth between my user accounts.

Is there anything that I am missing or that I did wrong acccording to the guide?

I'm not sure how the author of the guide solved this.

like image 879
frdmn Avatar asked Feb 17 '15 07:02

frdmn


People also ask

How to install brew for all users on Mac?

In System Preferences, go to Users & Groups, click the lock symbol in the bottom left corner to unlock user/group creation, then create a new group called brew-usergroup . Add all users who work with brew to the group (like in the attached screenshot from a german macOS).


2 Answers

Had to do this for my setup on Catalina 10.15.2 and followed these steps:

Note

I used the Users & Groups settings in System Preferences to make the brew group (choose group when making a new account). I added the execute permission to the group so that I could access a dart2native executable as the non-admin user.

I also used Cakebrew to manage all of the formulae after the configuration was running. I did notice a caveat where if user A has a file locked they will need to run brew cleanup in order to get a clean brew for User B.

When using brew cask install <appname> - you may experience issues if one of the users is not an admin and in that case, the admin user may need to do the install.

Other than those caveats everything seems to be working well.

Setup

(Assumes Allen is admin and Stan is not)

  • Create a group brew and add both Allen & Stan
  • brew doctor (Allen checks if he installed brew correctly)
  • sudo chgrp -R brew $(brew --prefix)/* (Change the group of homebrew installation directory)
  • sudo chmod -R g+w+x $(brew --prefix)/* (Allow group members to read, write and execute inside this directory)
  • brew doctor (Stan checks if he can use homebrew)

(source:https://medium.com/@leifhanack/homebrew-multi-user-setup-e10cb5849d59)

like image 37
Tommie C. Avatar answered Oct 14 '22 17:10

Tommie C.


I pieced the following together from a few posts, as I couldn't find everything needed in one place, such as a command for creating the group.

Works for me on macOS Mojave 10.14.4 (18E226).

brew-multiuser.sh:

#!/bin/bash

# Create a new group, brew
sudo dseditgroup -o create brew

# Change owner to brew group on brew assets
sudo chgrp -R brew $(brew --prefix)/*

# Change permissions to brew group
sudo chmod -R g+w $(brew --prefix)/*

# Add a user to the brew group
sudo dseditgroup -o edit -a userOne -t user brew

# Add another user to the brew group
sudo dseditgroup -o edit -a userTwo -t user brew

# Validate links, etc.
brew doctor

# Make any corrections from the `brew doctor` warnings, such as relinking.

# Run brew doctor to validate fixes
brew doctor

# Make sure it's working without error, with an update
brew update
like image 89
zslb Avatar answered Oct 14 '22 16:10

zslb