Sudo brew doesn't execute but changes hostname and path


I expect my issue is a user error, but I can’t figure out how to fix it so I came here for help.

I tried to run sudo brew install watchman, which gave me an error that said running brew as root is extremely dangerous and no longer supported. My terminal host name then changed from eriks-macbookair to ACC81EBE:. Typing hostname returns and I can no longer reach my node install, node: command not found, which leads me to believe the PATH variable somehow got modified too.

Any idea what I did or how I can fix it?

(Jonathan Chang) #2

There’s nothing in Homebrew that would change your hostname (search Github to confirm) so I’m not sure how we could help in this case.

(Gavan Schneider) #3

There are two levels to the OP report:

  1. sudo and brew are not good friends, and that’s the brewer’s policy.
    Simple test:
    $ brew --version
    $ sudo brew --version
    The second gives the error as reported and does not even supply the version number

2. this test did not cause me any hostname or other grief, i.e., pure invokation of brew does not cause the reported behaviour.
So there is an additional factor in the problem as reported by OP which is not obvious with the information given.

FWIW brew works just fine with: sudo su othuser provided the othuser is not $(id -u) -eq 0 (a.k.a. root).

Assuming this is a context specific problem possibly related to the less than graceful handling of the brew, do(/did) the host name changes and path problems persist after restart?

(Mike McQuaid) #4

Homebrew does not allow itself to be run by the root user for security reasons.

The hostname change will be unrelated; it’s likely your hostname changed at some other point when e.g. it was connected to AOL and it only refreshed on your machine afterwards. You can change it back. Homebrew also can’t and doesn’t modify your PATH variable. If you change your hostname back in System Preferences -> Sharing and open a new Terminal I suspect everything will be back to normal. If not, you can try brew reinstall node.


Thanks for the help. Resetting didn’t fix the host name problem, but I was able to isolate and fix it separately. It was an issue with resolving DNS and localhost that just happened to manifest itself at the same time I used homebrew.

I was not able to get node or any other packages installed with homebrew working again, but a complete uninstall of homebrew and all it’s packages, followed by a reinstall, following the suggestions made by brew doctor, and then another attempt at reinstalling node resolved the problem.

I’m not sure what the issue was, but it’s probably safe to assume it was user error. Thanks for your help.

(Mike McQuaid) #6

Glad you got it sorted.