11

Why brew installation needs sudo access?

Is it even safe to install brew as sudo?

/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"

==> Checking for `sudo` access (which may request your password).
Sorry, user XXX may not run sudo on XXXXXX.
Need sudo access on macOS (e.g. the user XXX needs to be an Administrator)!

I am super confused here and wondering is it ok to install brew with sudo or not?

Also why is it ok to install brew as sudo?

Exploring
  • 2,493
  • 11
  • 56
  • 97
  • The error is telling you that you need to install brew using an admin user. It needs access to /usr/local where it installs. If you try to prepend the command with sudo, I’m pretty sure it will warn you not to do that. – JBallin Mar 05 '21 at 06:32
  • https://docs.brew.sh/FAQ#why-does-homebrew-say-sudo-is-bad – JBallin Mar 05 '21 at 06:33
  • If you can’t use an admin user for some reason, you can try https://docs.brew.sh/Installation#untar-anywhere – JBallin Mar 05 '21 at 06:36
  • @JBallin so what I should be doing? you are saying prepend with sudo is bad as well. So how should I install brew correctly? I have admin user access. – Exploring Mar 05 '21 at 06:45
  • Homebrew doesn’t think you’re an admin. So you need to figure out why, and how to fix that. – JBallin Mar 05 '21 at 06:47
  • @JBallin thats what I am asking. Is it safe to install homebrew as a root user. – Exploring Mar 05 '21 at 06:53

2 Answers2

10

Homebrew doesn't need sudo access to install formulas and casks with brew install but it needs sudo access to install itself.

If you look at the official installation script, you will find 24 call to the execute_sudo function. They are related to creating directories, changing ownerships, installing Command Line Tools,...

All this is done to allow you to use Homebrew without sudo, but sudo is needed once for the Homebrew installation. So if you trust Homebrew you can install it with sudo privileges, it's part of the normal workflow.

Ortomala Lokni
  • 56,620
  • 24
  • 188
  • 240
1

I ran into this problem during my initial set up. As an admin logged in, I was not granted proper access so, what I did was I went to my User and Group settings and added the terminal unlocked to automatically log in. When I went to paste Homebrew again, it will ask for your password - which, I still thought was an error on my end because I could not visibly see my password being entered. once I entered it, you will have to wait a good 20 min or so before everything loads onto the terminal. Hope this helps.