install: improve handling of shared groups.

Closes #26184.