21

I am not sure why I'm getting this error:

$ brew install mongodb
==> Downloading http://fastdl.mongodb.org/osx/mongodb-osx-x86_64-2.0.4.tgz
######################################################################## 100.0%
Error: Permission denied - /usr/local/var/log/mongodb

So I try to run it with sudo:

$ sudo brew install mongodb
Password:
Cowardly refusing to `sudo brew install'

If I try to create the file myself I get this:

Error: File exists - /usr/local/var/log/mongodb

It gets even more interesting when you read this thread on homebrew's github about the error:

https://github.com/mxcl/homebrew/issues/9953

They state that brew can't write the file because it's not root, then they say it's because they think it shouldn't run as root.

These are the official install instructions, what's up?

If you have a better suggestion for installing it, then I'll forget about homebrew.

Eve Freeman
  • 32,467
  • 4
  • 86
  • 101
botbot
  • 7,299
  • 14
  • 58
  • 96

3 Answers3

54

The lazy (brew) way:

ls -al /usr/local/bin/brew #confirm brew ownership
sudo chown root:wheel /usr/local/bin/brew
sudo brew install mongodb
sudo chown <your user>:<your group> /usr/local/bin/brew  #revert ownership

The non-brew way:

Eve Freeman
  • 32,467
  • 4
  • 86
  • 101
  • i will go with the lazy way. i appreciate the effort, very informative. – botbot May 03 '12 at 04:44
  • i really like home brew package management, are there any advantages to not using home brew and just downloading manually as outlined above? – Nikola Sep 20 '13 at 03:07
  • you can manage which version you're running more easily (and use the development releases), and you end up understanding how mongodb works a little better. but for everyday developer use, it really doesn't matter. – Eve Freeman Sep 20 '13 at 03:12
  • Would you recommend that I create a `mongodb` folder inside `/usr/local/bin/` or rather just copy all the mongo files (mongo, mongod, etc) directly into `/usr/local/bin/`? – Nelu Oct 24 '13 at 04:06
  • how do I know what I do for : – SuperUberDuper Feb 28 '16 at 01:25
  • What this line do? "sudo chown root:wheel /usr/local/bin/brew", what is this "root:wheel"? When I run "ls -al /usr/local/bin/brew" I get "-rwxr-xr-x 1 root admin 1363 15 Nov 05:42 /usr/local/bin/brew" – Francisco Souza Nov 19 '16 at 12:37
  • @franziskux make it root:admin then. sounds like the new versions of mac os have a different admin account name. – Eve Freeman Nov 21 '16 at 23:31
  • Why should we revert ownership? Why don't we keep it this way? – User Mar 29 '17 at 19:25
4

I keep hitting this same problem over and over with different brew packages (today it was ImageMagick), so I keep coming back to this page. I'm just going to leave my version of the above instructions for myself, and maybe someone else will find it handy too

ls -al `which brew` # note user/group
sudo chown root:wheel `which brew`
sudo brew install <package name>
sudo chown <your user>:<your group> `which brew` # revert ownership

using which brew in back ticks substitutes your path to brew.

(and how do I escape backticks?)

stephan.com
  • 1,518
  • 18
  • 26
1

I kept getting this error before realizing-- I WAS SUDO SU'd!

In other words, I had a root prompt and was trying to run brew install . Do not try to install using brew if your command prompt has a # at the end.

I feel dumb about it, but maybe this will help someone else.