407

Brew doctor says:

Warning: /usr/local/include 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 header file to this directory, the install will fail during the link step.

You should probably chown /usr/local/include

I've tried different commands to solve this but I'm still stuck here.

I'm running homebrew on 10.8.2

gaggina
  • 5,369
  • 10
  • 31
  • 31

19 Answers19

808

Take ownership of it and everything in it.

Mac OS High Sierra or newer: (ty to Kirk in the comments below)

$ sudo chown -R $(whoami) $(brew --prefix)/*

Previous versions of macos:

$ sudo chown -R $USER:admin /usr/local/include

Then do another

$ brew doctor
jrwren
  • 17,465
  • 8
  • 35
  • 56
  • 15
    operation not permitted? – topwik Jan 29 '14 at 13:14
  • 69
    Any advantage instead of `$ sudo chown -R \`whoami\` /usr/local/`? – Labu Mar 05 '14 at 10:08
  • 2
    @WillemLabu one less process fork? whoami is effective user id and as the man page says is obsolete :) bash is default shell on OSX and somewhere USER is getting set. – jrwren Mar 05 '14 at 18:54
  • 1
    Oh, right. Thank you. I checked `man whoami` and that suggests `\`\`id -p\`\`` - that echoes uid and groups though. Your suggested `$USER` echoes just my username. Neat. – Labu Mar 06 '14 at 07:25
  • 7
    I wonder whether changing ownership of /usr/local to a user a clean solution. Wouldn't it be better to add $USER to the 'wheel' group? Or change the group of /usr/local to the admin group? – Michael Lehn Mar 18 '14 at 19:41
  • 1
    @MichaelLehn This is directly from homebrew documentation and homebrew depends on it. Given that most mac's are effectively single user computers and not shared systems, it does not matter, IMO. A group and maintaining g+w would be a bigger challenge given umask defaults to 022. Keeping umask of 002 in /usr/local and 022 elsewhere would be difficult. – jrwren Mar 18 '14 at 19:43
  • Does this properly undo the effect of `sudo make install`, or is this a "dirty" way? – shadowtalker Oct 01 '14 at 21:09
  • @ssdecontrol Yes, and this is by design and documented in homebrew. If you use homebrew you must (unless you want to deal with these warnings) commit all of /usr/local to homebrew. So you would never run sudo make install, homebrew would do that for you. – jrwren Oct 02 '14 at 17:42
  • @jrwren By "undo" I mean "undo with respect to system defaults." `chown` feels like a hack to me. Since I'm an admin user, I did `chmod g=u`; is there a reason `chown` is better? – shadowtalker Oct 02 '14 at 17:46
  • @ssdecontrol /usr/local is an empty folder or nonexistent by default, as for its ownership, I cannot tell you. Certainly this has no relation to a "sudo make install". But in short: Yes, this deviates from a default OSX install. – jrwren Oct 02 '14 at 17:48
  • @jrwren actually, I had no problems with Homebrew until I ran `sudo make install`, and, as you can see, `brew doctor` itself suggests that running `sudo make install` can cause this exact ownership problem. My guess is that library developers use hard-coded ownership/permission - modifying commands in their makefiles, but I also have no idea how makefiles work. – shadowtalker Oct 02 '14 at 17:50
  • @ssdecontrol it sounds like you have an entirely different issue. What software are you installing? Are you using homebrew to do it? If no, then use a different PREFIX than /usr/local. Also, because you already own /usr/local, there is no reason to use sudo. You can run make install. – jrwren Oct 02 '14 at 17:52
  • I was installing GSL manually to debug something, but that doesn't matter. I didn't realize `/usr/local` was created by Homebrew, so I guess the answer is "do what you want." Thanks for the clarification – shadowtalker Oct 02 '14 at 18:20
  • Taking ownership like this doesn't help for me. I still get the error that files are not writable... Any suggestion? – nclsvh Dec 03 '15 at 15:52
  • @NicolasV: Make sure you own /usr/local. –  Mar 11 '16 at 20:57
  • Doesn't work, throws `illegal user name` error on OS X 10.11.4. `sudo chown -R \`whoami\` /usr/local/` worked like a charm though. – Michał Miszczyszyn Apr 01 '16 at 11:53
  • How long does this command take to run? It's been going for about 5 minutes on my laptop and I have no way of knowing the status or progress. – ComputerScientist Oct 06 '16 at 16:58
  • 16
    According to [Homebrew](https://github.com/Homebrew/brew/issues/3228) in Mac OS High Sierra chown `/usr/local` doesn't work anymore. Instead use `sudo chown -R $(whoami) $(brew --prefix)/*` – Kirk Hammett Dec 07 '17 at 17:56
  • $ sudo chown -R $(whoami) $(brew --prefix)/* did the trick in mojavae 10.14 – Cyborgz Nov 05 '18 at 18:10
  • I got updated from Sierra to Mojave, and I needed to reinstall all brew to fix this error Now everything is working as intended – Arthur Melo Feb 26 '19 at 16:25
123

What worked for me was too

sudo chmod g+w /usr/local
sudo chgrp staff /usr/local
Durul Dalkanat
  • 7,266
  • 4
  • 35
  • 36
40

What worked for me was

$ sudo chown -R yourname:admin /usr/local/bin
Ana Isabel
  • 931
  • 1
  • 11
  • 21
39

The only one that worked for me on El Capitan was:

sudo chown -R $(whoami) /usr/local
Husky
  • 5,757
  • 2
  • 46
  • 41
27

If you are on High Sierra and experiencing this issue, follow the steps below (Note: /usr/local cannot be chown'd in High Sierra):

sudo mkdir /usr/local/include
sudo chown -R $(whoami) $(brew --prefix)/*

Then try linking with brew link. I was experiencing similar issue and none of the solutions above worked for High Sierra. Hope this helps someone.

Pro
  • 2,843
  • 1
  • 18
  • 29
  • 1
    I tried a lot. Brew doctor told that the dir is missing. Your answer helped me and am able to do the work. Thank you. Mac Users, Please try this. – Sankara Narayanan May 11 '22 at 02:37
24

For High Sierra:

/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

Then, try your brew commands.

Issue #3285

Mogsdad
  • 44,709
  • 21
  • 151
  • 275
Mahi
  • 472
  • 5
  • 7
  • 4
    Not sure why this was downvoted, if you previously had brew installed and upgraded to High Sierra, reinstalling Homebrew fixes the issue. This is the easiest approach – sam9046 Mar 05 '18 at 09:21
  • Ironically that's because the script does exactly what the other answers are suggesting. – Lightness Races in Orbit Aug 27 '19 at 16:48
  • This worked for me but first i uninstalled the previous using: ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/uninstall)" – abbas Nov 17 '19 at 21:21
12

You can alias the command to fix this problem in your .bash_profile and run it every time you encounter it:

At the end of the file ~/.bash_profile, add:

alias fix_brew='sudo chown -R $USER /usr/local/'

And now inside your terminal you can run:

$ fix_brew
karlingen
  • 13,800
  • 5
  • 43
  • 74
12

This worked for me on macOS 10.12

sudo chown -R $(whoami) /usr/local

I had the problem updating homebrew with the following error:

/usr/local is not writable. You should change the ownership
and permissions of /usr/local back to your user account:
  sudo chown -R $(whoami) /usr/local
Max
  • 146
  • 1
  • 4
9

First you need to create the directory:

sudo mkdir /usr/local/include

Second:

sudo chown -R $(whoami) $(brew --prefix)/*
Matthew
  • 1,905
  • 3
  • 19
  • 26
gugapc
  • 214
  • 3
  • 2
8

For some it's going to be:

sudo chown -R JonJames:admin /usr/local/lib

where "lib" is used as opposed to "bin" or "include" or "whatever else"

The Homebrew Warning "should" explain what specifically is not writable and then give you a command syntax for follow, however you will need to use the ":" as opposed to what the Warning mentions which is actually not correct syntax??

Jonathan James
  • 219
  • 2
  • 7
  • The syntax in the Warning is a bit confusing I believe, I emailed the lead contributor for Homebrew to ask if they would change anything about it, awaiting reply, perhaps the Warning's verbiage will change in future brew updates.. – Jonathan James Dec 21 '15 at 22:46
  • thanks! This worked after a fair amount of searching around. – thiswayup Apr 19 '16 at 03:45
7

Work for me

$ sudo chown -R $(whoami):admin /usr/local

$ cd /usr/local/Library && git stash && git clean -d -f
5

Same error on MacOS 10.13

/usr/local/include and /usr/local/ /usr/lib were not created. I manually created and brew link finally worked.

cSteusloff
  • 2,487
  • 7
  • 30
  • 51
Miguel
  • 51
  • 1
  • 1
4

What Worked for me, while having I have more than 1 user on my computer.

Using terminal:

  • Running brew doctor
    • Seeing multiple /usr/local/... isn't writable error's
  • Disabling Mac's System Integrity Protection: https://apple.stackexchange.com/a/208481/55628
  • Run the following
  • sudo chown -R $(whoami) /usr/local/*
  • brew doctor && brew upgrade && brew doctor

Running Macbook Pro OSX High Sierra (version 10.13.3.)

EDIT 1:

FYI - Please be Advised this causes an issue with running MySQL on your MAC.

To be able to start my local server, I had to run:

sudo chown -R mysql:mysql /usr/local/mysql/data

After you run this you can start your local MySQL Server.

JayRizzo
  • 3,234
  • 3
  • 33
  • 49
3

You need to create /usr/local/include and /usr/local/lib if they don't exists:

$ sudo mkdir -p /usr/local/include
$ sudo chown -R $USER:admin /usr/local/include
3
sudo mkdir -p /usr/local/include /usr/local/lib /usr/local/sbin

sudo chown -R $(whoami) /usr/local/include /usr/local/lib /usr/local/sbin

This will create all required directories and give it the correct ownership.

After running these commands check with: brew doctor

This works for Mojave.

Paul Roub
  • 36,322
  • 27
  • 84
  • 93
Sven
  • 31
  • 1
2

You need to get control of entire /usr/local to do that you need to do a recursive chown under /usr/local

sudo chown -R YOUR_USERNAME:admin /usr/local/

add-semi-colons
  • 18,094
  • 55
  • 145
  • 232
2

I just want to echo sam9046's modest comment as an alternative and potentially much easier solution that worked in my case: uninstall and install homebrew again from scratch. No sudo commands required.

You can also browse/modify the uninstall script from that link above if you need to ensure it won't affect your previously installed packages. In my case this was just my home machine so I just started over.

adamkski
  • 21
  • 1
  • 1
1

I have had this happen in my organization after all our users were bound to active directory (effectively changing the UID from 50x to ######).

Now it is simply a case of changing the ownership of all files where were owned by x to y.

Where 501 is my old numeric user id which is still associated with all the homebrew files.

The old user id can be found using ll /usr/local/Cellar

Now update the ownership sudo find /usr/local -user 501 -exec chown -h $USER {} \;

This way we avoid changing the ownership on files which are not controlled by homebrew or belong to some other system user.

Tarun
  • 2,039
  • 1
  • 15
  • 5
1

Go into the /bin directory and type:

chown -R $(whoami):admin /usr/local/bin

Yusuf
  • 2,459
  • 1
  • 12
  • 5