Skip to content
This repository has been archived by the owner on Jul 4, 2023. It is now read-only.

Cowardly refusing to `sudo brew install' #9953

Closed
Velrok opened this issue Feb 3, 2012 · 42 comments
Closed

Cowardly refusing to `sudo brew install' #9953

Velrok opened this issue Feb 3, 2012 · 42 comments

Comments

@Velrok
Copy link

Velrok commented Feb 3, 2012

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 ?

@jacknagel
Copy link
Contributor

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

@jacknagel
Copy link
Contributor

(this is by design.)

@Velrok
Copy link
Author

Velrok commented Feb 3, 2012

Thanks. Works now.

@kittles
Copy link

kittles commented Apr 20, 2012

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

@diek
Copy link

diek commented Apr 27, 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
Copy link

Jtiem commented Apr 28, 2012

So how do I assign root privileges to brew?

@jacknagel
Copy link
Contributor

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
Copy link

alper commented Jun 13, 2012

That's an odd and off putting error message.

@rayray
Copy link
Contributor

rayray commented Jul 3, 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.

@jacknagel
Copy link
Contributor

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.

@mikemaccana
Copy link

+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.

@rexmortus
Copy link

+1 for changing the error message.

@mxcl
Copy link
Contributor

mxcl commented Aug 10, 2012

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

@mxcl
Copy link
Contributor

mxcl commented Sep 22, 2012

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.

@jacknagel
Copy link
Contributor

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.

@MikeMcQuaid
Copy link
Member

@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.

@Sharpie
Copy link
Contributor

Sharpie commented Sep 22, 2012

(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.

@mikemaccana
Copy link

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

@mxcl
Copy link
Contributor

mxcl commented Sep 24, 2012

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
Copy link

henri commented Oct 7, 2012

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).

@mxcl
Copy link
Contributor

mxcl commented Oct 9, 2012

@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.

@kirai
Copy link

kirai commented May 20, 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.

@mistydemeo
Copy link
Member

@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.

@kirai
Copy link

kirai commented May 20, 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 ;)

@mistydemeo
Copy link
Member

@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
Copy link

henri commented Nov 5, 2013

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
Copy link

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.

@MikeMcQuaid
Copy link
Member

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

@Michael-Getzinger
Copy link

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...

@MikeMcQuaid
Copy link
Member

chown -R $USER /usr/local

@SplashDance
Copy link

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

@MikeMcQuaid
Copy link
Member

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

@SplashDance
Copy link

Hey thanks @MikeMcQuaid -- I'm embarrassed that the solution was so easy...

@MikeMcQuaid
Copy link
Member

I'm embarrassed that my first message wasn't more clear 😄

@adrianboston
Copy link

change owner of brew to root, which is common for files in /usr/local directory ( opposed to either /home or /Users )

sudo chown root /usr/local/bin/brew

and/or add the admin group
sudo chown root:admin /usr/local/bin/brew

@sdupd-gbatuyong
Copy link

I think the problem stems from the installation. When brew is installed the first time using the ruby one-liner, it first refuses to do so with sudo privileges. Fair enough, so it does its thing then now the executable is owned by the user:admin. Great, next step you want to install something like irssi… so "brew install irssi" which works all up until I get "Permission denied" errors linking to perl5 in /usr/local/bin… Well how do we get around that, normally? I use "sudo !!" to re-run the command with some authority, at which I'm confronted with the refusal error. So what's happening here is a funnel process where the user has no solution after following directions to the letter —and the only documented workaround is to muck with permissions, which tosses out the user experience, compared to say, MacPorts. What's the elegant way to do this?

[UPDATE] It seems a lot of the interesting wisdom is found when running brew doctor. THAT should be part of the initial install process because it identifies problems that may not be entirely obvious for console/UNIX newbies.

@jacknagel
Copy link
Contributor

When brew is installed the first time using the ruby one-liner, it first refuses to do so with sudo privileges. Fair enough, so it does its thing then now the executable is owned by the user:admin. Great, next step you want to install something like irssi… so "brew install irssi" which works all up until I get "Permission denied" errors linking to perl5 in /usr/local/bin… Well how do we get around that, normally?

On a clean install this does not happen. If you get permissions errors right off the bat, then there was already stuff installed into /usr/local, and it had different permissions.

It seems a lot of the interesting wisdom is found when running brew doctor. THAT should be part of the initial install process because it identifies problems that may not be entirely obvious for console/UNIX newbies.

The last thing the installer does is instruct the user to run brew doctor:

https://github.com/Homebrew/install/blob/4afb9e930b6b8369f8d5032d6c8fb47ff997665e/install#L209-L210

@Homebrew Homebrew locked and limited conversation to collaborators Nov 5, 2014
@MikeMcQuaid
Copy link
Member

@jacknagel I really think the installer should just chown -R /usr/local or at least all the directories that we chmod.

@MikeMcQuaid
Copy link
Member

@jacknagel Any objections to me just doing that?

@jacknagel
Copy link
Contributor

We already chgrp everything, right? What's missing?

@MikeMcQuaid
Copy link
Member

I'll try and take a look.

@MikeMcQuaid
Copy link
Member

@jacknagel Had another look and you're right. Apologies.

marks added a commit to untoldone/bloomapi that referenced this issue Nov 11, 2014
`brew` should be run as the current user (in most cases, per Homebrew/legacy-homebrew#9953) and pdftotext is included in the xpdf brew package.
marks added a commit to untoldone/bloomapi that referenced this issue Nov 26, 2014
`brew` should be run as the current user (in most cases, per Homebrew/legacy-homebrew#9953) and pdftotext is included in the xpdf brew package.
untoldone pushed a commit to untoldone/bloomapi that referenced this issue Dec 3, 2014
`brew` should be run as the current user (in most cases, per Homebrew/legacy-homebrew#9953) and pdftotext is included in the xpdf brew package.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests