MacOS – Which is the correct way to obtain administrator access for the installation of Homebrew

homebrewmacos

I usually log in to OS X El Capitan without administrator rights. Homebrew upholds the principle that packages can be installed and used without administrator/root access, i.e. without using the sudo command.
However, it seems that administrator access is necessary for installing Homebrew. Running the script from my normal non-admin user's Terminal yields

This script requires the user [user] to be an Administrator. If this
sucks for you then you can install Homebrew in your home directory or
however you please; please refer to our homepage. If you still want to
use this script set your user to be an Administrator in System
Preferences or `su' to a non-root user with Administrator privileges.

First, unfortunately, the homepage does not say much more about how to install in my home directory and what difference that actually makes from the usual way to install.

Second, running 'su' and entering my password yields

su: Sorry

Then, running 'sudo su' yields

[user] is not in the sudoers file. This incident will be reported.

This did not feel right, either. (See also Why can't I run `su`? (and how should I do?))

Third, I simply opened a shell with my administrator account 'login [user-admin]' to install Homebrew. But when I later tried to install a package as the normal non-admin user/ran 'brew doctor', I did get a number of errors about directories not being writable. Again, a fix is suggested at https://stackoverflow.com/questions/14527521/brew-doctor-says-warning-usr-local-include-isnt-writable but I was not too sure whether there is only one /usr/local on my computer, or whether there is one for every user so that the directories in question would actually be those of my admin user (and thus it might be weird to give my non-admin user access to those). Also, it were quite many directories (more than 10) which made me suspicous.

Forth, and finally, what I did was to give my non-admin user administrator rights, installed as that user, and then made the user a normal, non-admin user again.

Now, everything seems to be OK, but I wonder whether this was actually the/a correct way, since the script error quoted above didn't actually say whether I need to permanently have Administrator priviledges, or whether it is OK to only take them during the installation process of Homebrew itself.

Best Answer

The normal way to do things is as per your third choice ie use an admin account to install things.

However Homebrew's normal setup does not stick to normal Unix conventions of installing excutables as root or a special user which would allow equal access of the installed code to all users, it is designed so that you do installs as one user and so do not need to use sudo/su for anything. However to do this it needs to make /usr/local writeable by the normal user and you need admin rights to that as in the way you did in the end. I think Homebrew really is designed for a computer which only one person uses and has admin rights.

If you do not want to (or cannot) set your user to admin then there are two ways

  1. As per the instructions you quote "If this sucks for you then you can install Homebrew in your home directory" Then the access to ~/usr/local is always for the user
  2. A version of your 3. The Homebrew script leaves /usr/local and all under it owned by the user doing the installation. With the admin user you can change the owner to your normal user by chown -R usr /usr/local

Yes there is only one /usr/local in the file system. Each path is unique. The way to have the "same" directory for different users is to put the directories under your home directory e.g. ~/usr/local