Why brew never asks for a password?

3

I have been an Ubuntu user for the last 3 years and now I shifted to Mac OS X. I set my account to be an admin user, and have my own space at /Users/<my-username>.

Each time I used to install packages on my Ubuntu, it asked for my root password and I have to do it by prefixing it with sudo. But here in OS X, I can simply do a brew install. I understand I am a root user(have admin rights), so I don't need to use sudo, but for starting the services like mongod, I have to use sudo. Why so?

I am not getting it; can anybody explain?

darxtrix

Posted 2016-09-16T06:52:44.560

Reputation: 133

Answers

3

Homebrew not only does not require sudo, but warns against using it.

Homebrew stores the files in the "user space" (under /usr/local branch) and does not touch the system directories.

Executable files are kept in /usr/local/bin, configuration files in /usr/local/etc, packages in /usr/local/Cellar. Neither of these directories require administrative permissions to write files (by default an owner and members of the group admin have full permissions to these directories).

On Ubuntu you are asked for administrative permissions, because packages installed by APT store their files and configuration in system directories (like /etc, /usr/bin) which by default do not allow being modified by a regular user.

On the other hand, if you run a program it might require administrative permissions to perform certain actions (like registering as a service). This requirement is separate from the rights to read/write files (belonging to the package) and in these cases both Ubuntu and Mac OS X require sudo.

techraf

Posted 2016-09-16T06:52:44.560

Reputation: 4 428

Thanks, why does it warns against using it ? – darxtrix – 2016-09-16T07:16:39.580

1@ankcodes Because it was designed to be run as a regular user. The problem is that if you use it once with sudo, then root account will own all newly created directories. If you then run it as a regular user, it won't be able to upgrade or delete old packages. – techraf – 2016-09-16T07:21:14.353

This helps a bit more, http://askubuntu.com/a/308048/340132 . Thanks :)

– darxtrix – 2016-09-16T07:26:39.580