A Linuxbrew install belongs to the account that created it. I installed Homebrew on my Linux machine under one user account, then set up a second account and assumed the only remaining step was dropping the shell env line into .bashrc. It wasn't. Sharing one brew install across multiple users takes two fixes, in this order: group permissions on the install tree, then Git safe directory entries.
The steps below assume you installed Homebrew on Linux the normal way, at the default prefix /home/linuxbrew/.linuxbrew. The first error is straightforward:
Error: /home/linuxbrew/.linuxbrew/Cellar is not writable.
The fix is to create a shared group, add both users to it, and set group ownership and permissions on the entire Homebrew tree:
# Create a shared group
sudo groupadd linuxbrew
# Add both users
sudo usermod -aG linuxbrew user1
sudo usermod -aG linuxbrew user2
# Set group ownership and permissions
sudo chgrp -R linuxbrew /home/linuxbrew/.linuxbrew
sudo chmod -R g+rwx /home/linuxbrew/.linuxbrew
# Set the setgid bit so new files inherit the group
sudo find /home/linuxbrew/.linuxbrew -type d -exec chmod g+s {} \;
# Let the second user traverse the parent directory
sudo chmod 755 /home/linuxbrewLog out and back in for the group membership to take effect.
After fixing permissions, brew update started throwing a different error:
Warning: No remote 'origin' in /home/linuxbrew/.linuxbrew/Homebrew, skipping update!
fatal: detected dubious ownership in repository at '/home/linuxbrew/.linuxbrew/Homebrew'
This is Git's safe-directory check, and it is the same detected dubious ownership in repository error you get on any repo owned by another account. The Homebrew repo is owned by the first user, so Git refuses to operate on it when the second user runs brew. The fix is to mark the Homebrew directories as trusted for the second user:
git config --global --add safe.directory /home/linuxbrew/.linuxbrew/Homebrew
git config --global --add safe.directory /home/linuxbrew/.linuxbrew/Homebrew/Library/Taps/homebrew/homebrew-core
# add any other tap paths that show up in the errorAfter that, brew update ran cleanly and everything worked as expected.
To share a Linuxbrew install across accounts: fix group ownership so both users can write to the cellar, then mark the Homebrew Git repos as safe directories for each additional user. Two separate problems, two separate fixes. Neither is complicated once you know what you're looking at.
Occasional notes on software, tools, and things I learn. No spam.
Unsubscribe anytime.