MacOS – How to link /usr/local to user specific directory

filesystemhomebrewmacosmount

Is it possible to map the /usr/local/ path on MacOS to a directory that is unique for each user, for example ~/local/? Or is there another way to solve the following:

I trying to give each user on my MacOS server a personal homebrew installation. However the disadvantage of installing homebrew in a non-standard user directory is that all packages will need to be rebuilt from source. Homebrew only uses the binary bottles for the default /usr/local dir.

Preferably I would like each user to have a copy of homebrew in their home dir, and somehow map the /usr/local path to that directory so that the binaries still work.

Best Answer

Yes, you can do it - but it is relatively involved.

Essentially you could chroot each user into his own directory and replicate the filesystem in there, except for the /usr/local directory, which would then be user-specific.

To access the system directories inside the chroot, you could use bindfs, osxfs or even a NFS mount.

Far easier to just let each user have a non-default homebrew and let them rebuild all their packages as needed. By definition, not sharing one folder implies duplicate storage and work but that’s likely far less hassle to set up.