I'm trying to install unbound using brew command.

Here's output for brew install unbound:

Warning: unbound 1.6.7 is already installed, it's just not linked.
You can use `brew link unbound` to link this version.

As you can see, I was asked to use brew link unbound to link to unbound 1.6.7.

But I failed to link to it because I got the following error:

Linking /usr/local/Cellar/unbound/1.6.7...
Error: Could not symlink sbin/unbound
/usr/local/sbin is not writable.

I've the other stackoverflow here.

And the answer sudo chown -R $(whoami) /usr/local creates the following error:

chown: /usr/local: Operation not permitted

I'm using macOS High Sierra Version 10.13.2. And my homebrew version is 1.4.3.

How can I solve this problem?

  • Please add in your OQ which version of MacOS is concerned by your problem.
    – dan
    Jan 15 '18 at 10:09
  • Have you tried running as sudo? Jan 15 '18 at 12:18
  • brew refuses to work with sudo Sep 8 '19 at 0:28

By default /usr/local/sbin doesn't exist. The folder should be created by installing brew, the owner/permissions are set to $(whoami):admin/775. Most/all folders in /usr/local/ are owned by the user who installed brew - that's part of the default installation and configuration.

On the other hand some third-party tool may have been installed to this folder previously (e.g AFAIR procexp or Smartmontools have to be installed there). Then the owner/permissions are probably set to root:wheel/755 or root:wheel/775

To solve your problem check whether /usr/local/sbin exists and its folder permissions.

The following command creates this folder if it doesn't exist and makes it world writable, but doesn't change owner:group:

if [ ! -d /usr/local/sbin ]; then sudo mkdir /usr/local/sbin; fi && sudo chmod 777 /usr/local/sbin

Now you can link unbound:

brew link unbound

You may undo the world writable step with:

sudo chmod 775 /usr/local/sbin

Don't forget to add the folder to your user's PATH in ~/.bash_profile or the system's PATH in /etc/paths.

If you get the error:

Error: Could not symlink sbin/unbound
/usr/local/sbin is not writable.

the user doesn't have permissions to write to the folder with the command actually executed.

The command sudo chown -R $(whoami) /usr/local will change the owner of all subfolders and their content to $(whoami) despite the error chown: /usr/local: Operation not permitted. The only exception will be a SIP protected item in /usr/local/. By default none of the files and folder is protected though.

Thus the error message is erroneous and you probably already have been successful by entering your sudo chown -R ... command and you should have tried to simply linked unbound once more.

You can check the folder permissions by entering:

ls -lae /usr/local/sbin

You can get all a protected items in subdirectories of local by entering:

ls -lae -R /usr/local | grep restricted

Running brew doctor did the trick for me.

It diagnoses all manner of missing folders, folders with permissions that are known to cause problems and other fix ups you might need to perform after another process changes things or things just break.


Running brew doctor will diagnose the issues for you.

For me sudo mkdir -p /usr/local/sbin and sudo chown -R $(whoami) /usr/local/sbin did the trick. Then I linked it to php by running brew link php

And also sometimes you need to add:

echo 'export PATH="/usr/local/sbin:$PATH"' >> ~/.bash_profile

and restart the terminal.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .