Skip to content
This repository

Cowardly refusing to `sudo brew install' #9953

Closed
Velrok opened this Issue February 03, 2012 · 32 comments
Waldemar

Got:

user$ sudo brew install ruby
Cowardly refusing to `sudo brew install'
root@mashine$ brew install ruby
Cowardly refusing to `sudo brew install'
sh: parse_git_branch: command not found
sh: parse_svn_branch: command not found

Is this related to #6899 ?

Jack Nagel
Owner

brew install will not work with root privileges unless brew itself is owned by root.

Jack Nagel
Owner

(this is by design.)

Jack Nagel jacknagel closed this February 03, 2012
Waldemar

Thanks. Works now.

Patrick Brooks

why not make "brew install will not work with root privileges unless brew itself is owned by root." the error message?

derrick kearney
diek commented April 26, 2012

This reminds of the article "Writing Unmaintainable Code", a sarcastic look at the stuff programmers do to make things incomprehensible. "Much of the skill in writing unmaintainable code is the art of camouflage, hiding things, or making things appear to be what they are not." Why would they want us to really understand what is going on? They make us come to a forum like this one, so they can make us look dumb. I have been using linux for about 6 months and I just bought a Mac because I was tired of MS controlling stuff and annoyances. Over the past 2 weeks I have gained a new enemy, the mayhem and chaos that is the support for some open source software. After painfully uninstalling 2 programs from the Mac I looked around and a search of the internet brought me to Home brew to manage installs. Only to discover it too comes with errors, whose solutions lead me in a circle. issue 10234

Jtiem
Jtiem commented April 27, 2012

So how do I assign root privileges to brew?

Jack Nagel
Owner

The brew executable itself has to be owned by root. Note that we do not support this in any fashion, and actively recommend against it.

Alper Cugun
alper commented June 13, 2012

That's an odd and off putting error message.

rmndk
rmndk commented July 03, 2012

@jacknagel Well, then why should I have to change permissions on /usr/local/include? I never changed them in the first place, but I'm not allowed to sudo brew link xz.

Jack Nagel
Owner

Sigh. I'm tired of dealing with this.

These are your options:

(a) don't use sudo; adjust the permissions on directories in /usr/local accordingly. This is the recommended way to use Homebrew.

(b) chown the brew executable to root; and use sudo as you please. This is fine, but is not supported.

The Homebrew issue tracker is not a place to have debates about basic UNIX filesystem management. If you already have a basic understanding of these things, then you have the tools to manage Homebrew however you like at your disposal.

Mike MacCana

+1 ditching this in favor of a useful error message.

@jacknagel: I imagine you're very tired indeed - fixing the error message to include something like your comment above will help avoid these unnecessary discussions:

"Refusing to run via sudo. brew should be able to write to /usr/local/Cellar without requiring root access. " or similar.

Alec Sloman

+1 for changing the error message.

Max Howell
Owner
mxcl commented August 10, 2012

I like the way people assumed I was making it incomprehensible on purpose.

Max Howell
Owner

The error message now includes (since ages):

You can use brew with sudo, but only if the brew executable is owned by root.
However, this is both not recommended and completely unsupported so do so at
your own risk.
Jack Nagel
Owner

AFAICT, only one person on this thread was being a 'dick' and making accusations, so i think you should cool off a little

Nobody called anyone a 'dick'.

LOL. Thanks for the lecture though.

Mike McQuaid

@rosssclafani This sort of argument has no place on an issue tracker so I've deleted your last two comments and will continue to delete any more you make on this issue.

Charlie Sharpsteen
Owner

(b) chown the brew executable to root; and use sudo as you please. This is fine, but is not supported.

I wouldn't say that is fine. Anyone who does that is playing with fire and will get what they deserve.

The reason being: Homebrew makes no attempt to drop permissions where appropriate so every action taken by sudo brew occurs with full root authority. This means a bug that would normally fail with "insufficient privileges" may turn into "oh hai, I just ate your hard drive. Have a nice day!".

It gets worse than that. Every configure script, every make invocation, everything will be run as root. So, not only do you have to worry about any terrible bugs we have lying around in our code, you also have to worry about what may be lurking in the 2200+ projects that brew installs.

Bottom line: don't run brew as root. You really don't want to.

Mike MacCana

Thanks Max! Much appreciated & sorry about all the drama on this thread.

Max Howell
Owner

My fault. I shouldn't have been sensitive about it, higher things are expected of me.

But for the record: we'll improve anything and everything.

henri

I am a home brewing noob. I downloaded it less than an 30 min ago. As such, please take the information in this post with a grain of salt. Comments and suggestions would be welcome. I am making many assumptions and best guesses. I am sure that many old time brewers will be able to provide advice and improve the comments and instructions listed below.

One option could be to have a brew (maybe brewer) user and perhaps even a brew (maybe brewer) group is an option for the future. With such a user and group, projects could be installed by this user/group by default. You could of course have projects installed by other users. But this could be a starting point?

In the mean time. If you are seeing the message listed below and have already installed Home Brew then the steps below should get you up and running (skip the ones relating to install of home brew). I stumbled across this thread because I was not sure what to do when I saw this message and used the google to find out more. Chances are you may have also found this page in the same manor. In which case just as well I wrote something to help you out.

Error: Cowardly refusing to `sudo brew install' You can use brew with sudo, but only if the brew executable is owned by root. However, this is both not recommended and completely unsupported so do so at your own risk.

Hopefully, the following information will save someone some time. If you have more experiencing using Home Brew (I imagine most people who have commented on this thread will have more experience than myself) then please correct or suggest that I update the instructions below. The instructions below assume that you are a member of the 'admin' group on the system. If a future version of Home Brew sets up a 'brewer' group then I suppose it would just be a matter of adding yourself and others who will be brewing to that group.

  • #install developer tools, install the developer command line
  • ruby -e "$(curl -fsSkL raw.github.com/mxcl/homebrew/go)" #install brew, enter password when prompted.
  • brew doctor # make sure the install is all good, enter password when / if prompted.
  • sudo su #login to a root shell
  • mkdir /usr/local/Cellar
  • chown root:admin /usr/local/Cellar # alter owner, if there was a brewer group then change admin to brewer.
  • chmod 775 /usr/local/Cellar # allow people within the admin group to write to the /usr/local/Cellar directory.
  • #consider further restrictions on this directory (e.g. sticky bit?)
  • exit # drop back to a non root shell
  • brew install wget # try to install something (in this example wget).

If someone would like to copy / update this list then perhaps it could be put into the Home Brew wiki or quick help. Then I can just edit this post so that it links to that information (which could be kept upto date).

Max Howell
Owner

@henri The only steps required are:

  • Install the Command Line tools for Xcode
  • ruby -e "$(curl -fsSkL raw.github.com/mxcl/homebrew/go)" #install brew, enter password when prompted.

I'd be interested to understand why the rest were necessary for you.

Hector Garcia
kirai commented May 19, 2013

Even if "this is by design" it feels very uncomfortable and weird for me AS A USER to run a command using "sudo" and not being able to do so. It is a weird behavior that I did not expect as a user.

Misty De Meo
Owner

@kirai If you want to run brew as sudo, you can chown the brew executable. We intentionally don't let brew be run as sudo otherwise, because the result will be that further non-sudo brew usage will fail.

You're right that the messaging could be better, though.

Hector Garcia
kirai commented May 19, 2013

Yes, thanks @mistydemeo ! That is what I did and it works but I had to google it etc. As you say, the error message could give some clue to the user on why brew is cowardly refusing to do what I'm telling it to do ;)

Misty De Meo
Owner

@kirai Actually, I see that (as Max points out above) the error is very specific to what the problem is, and has been since at least August! If you're not seeing it, you should brew update. See: 2f8f17f.

henri

If you are not running as an administrator on the system then you will not have write access to /Applications. I have found the best way to get around all these issue when using homebrew (which is awesome software by the way) on a system which you are not normally the admin of is to simply login into an administrator account and then it all seems to work very well.

Again, thank you for creating, releasing and offering all the support. It is such a great way to manage packages on OS X systems :)

James Barnard

I got here because mac osx instructed me to re-run the brew install * command as sudo. The real issue was that I had just installed the xcode command line tools and had not accepted the xcode license agreement yet and that requires root. The solution is to call a simple command with xcrun (like sudo xcrun git status) and review and sign the agreement when prompted. Then you can get back to work brew installing whatever you please.

Mike McQuaid
Owner

OS X told you to run sudo xcode-select --install perhaps but it certainly did not tell you to run brew install as sudo.

Tiem Song tiembo referenced this issue from a commit January 02, 2014
Commit has since been removed from the repository and is no longer available.
GitHub-NYC

I wish I knew what "adjust the permissions on directories in /usr/local accordingly" meant (exactly)?

To clarify my question, I noticed "mxcl" commented:

 "The only steps required are

      Install the Command Line tools for Xcode

      ruby -e "$(curl -fsSkL raw.github.com/mxcl/homebrew/go)" #install brew, enter password when prompted.

 I'd be interested to understand why the rest were necessary for you."

But how can these be the "only steps required" when "jacknagel" also wrote the following?

 "(a) don't use sudo; adjust the permissions on directories in /usr/local accordingly. This is the recommended way to use Homebrew."

Is the answer to simply chmod 775 for any subdirectories under "/usr/local"?

Is it also necessary to "chown root:admin" for all subdirectories of "/usr/local/" as "henri" was asking?

As for the default "sudo brew" error message, while it explains that you may use "sudo", it also says it is not recommended (which makes sense to me). I think it would be far more helpful if the error message mentioned something about changing permissions for directories under "/usr/local", since that IS recommended... and seemingly required.

Thanks all...

Mike McQuaid
Owner

chown -R $USER /usr/local

Steve

@mikemcquaid : What are you supposed to do when running that command spits out a thousand lines of Operation not permitted error messages?

Mike McQuaid
Owner

@SplashDance sudo chown -R $USER /usr/local

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.