MacOS – How to resolve permissions errors on OS X Lion after Homebrew install

grouphomebrewmacospermission

I just upgraded from Snow Leopard to Lion and am trying to get Homebrew installed. However after the installation, I run brew doctor per the installation instructions, and see a series of errors indicating that /usr/local directories aren't writable. For example:

Error: /usr/local/share isn't writable.
This can happen if you "sudo make install" software that isn't managed
by Homebrew.

If a brew tries to write a file to this directory, the install will
fail during the link step.

You should probably `chown` /usr/local/share

I get these for a bunch of directories:

You should probably `chown` /usr/local/include

You should probably `chown` /usr/local/share

You should probably `chown` /usr/local/share/man

I can't figure out why this error is coming up, as it appears that I am part of the Unix group that has write permissions to these directories:

Mini:~ felciano$ ls -ld /usr/local/share
drwxrwxr-x  4 root  admin  136 May 13 15:53 /usr/local/share
Mini:~ felciano$ whoami
felciano
Mini:~ felciano$ dscl . -read /Groups/admin GroupMembership
GroupMembership: root felciano
Mini:~ felciano$

What am I missing?

Best Answer

EDIT: The problem is now fixed in Homebrew:

If you still experience the problem, update Homebrew like this:

brew update

If you want to know what the problem was, I have kept my original answer below.


Ignore the permisson issue for now

I am experiencing the exact same problem and in my opinion the problem is in brew doctor rather than in your and my installation.

I think you should ignore the issue rather than changing the ownership of /usr/local. Alternatively, you could fix your local brew doctor script until a fix is released. See below.

I don't consider it correct to make /usr/local owned by a specific user. I have more than one admin user on this machine. You should leave /usr/local owned by root:admin as owner and group.

My investigation

Like for you I have a /usr/local that is perfectly writable by my user which is also a member of the admin group:

$ ls -ld /usr/local/
drwxrwxr-x  14 root  admin  476 22 Jun 23:33 /usr/local/
$ whoami
mgd
$ dscl . -read /Groups/admin GroupMembership
GroupMembership: root mgd rgd

Let's test that the dir is really writable:

$ ls -l /usr/local/newfile
ls: /usr/local/newfile: No such file or directory
$ touch /usr/local/newfile
$ ls -l /usr/local/newfile
-rw-r--r--  1 mgd  admin  0 23 Jun 14:52 /usr/local/newfile

Further investigation into the brew doctorcode led my to the conclusion that the use of the ruby function Pathname.writable? is causing the problem. Consider this interactive Ruby session:

$ irb
>> require 'pathname'
=> true
>> Pathname('/usr/local').writable?
=> false

Function Pathname.writable? says /usr/local is not writable even though we know it is.

Using Pathname.writable_real? instead gives the correct result – it says that the dir is writable:

>> Pathname('/usr/local').writable_real?
=> true

This should be fixed in /usr/local/Library/Homebrew/cmd/doctor.rb. You can fix it in your own installation while waiting for a fix.

The difference between the two functions are (according to the Ruby docs here and here):

writable?(file_name) → true or false: Returns true if the named file is writable by the effective user id of this process.

writable_real?(file_name) → true or false: Returns true if the named file is writable by the real user id of this process.