permissions - writable - can't chown/usr/local for homebrew in Mac OS X 10.13 High Sierra

reinstall homebrew high sierra (8)

I did not have the /user/local/Frameworks folder, so this fixed it for me

sudo mkdir -p /usr/local/Frameworks
sudo chown -R $(whoami) /usr/local/Frameworks

I have OSX High Sierra

Homebrew needs permissions in /usr/local and since no one else uses my laptop I have always simply done

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

but in High Sierra, this gives

chown: /usr/local: Operation not permitted

What is the fix?

I followed this but the problem still persist.
So, I reinstalled homebrew without uninstalling previous one. It's working now!
(I don't know how)

Make sure you don't have a lock set on the home folder or any folder an install needs access to.

Even if the permissions and ownership are set correctly and you are currently logged in with a correct user/or Root user it will not allow you to make new folders or directories.

Problem still persists in latest MacOS i.e. Mojave . Uninstalling and reinstalling Homebrew doesn't solve the directory permission problem. In fact it's not related to Homebrew installation at all!

When we do brew install python it simply pours brew python and then tries to create symbolic link under /usr/local dir which brew doesn't have permission for. And when we try to execute sudo chown -R $(whoami) /usr/local it doesn't work because it requires extra privilege which normal mac users (i.e. your username) don't have. But as @Reza mentioned in his answer permission of any directory underneath can be changed. simply issue following command:

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

Try disabling System Integrity Protection . From the documentation:

System Integrity Protection can be configured using the csrutil(1) command.

You can check whether System Integrity Protection is currently enabled on your system by running the following command in the Terminal:

$ csrutil status
System Integrity Protection status: enabled.

To enable or disable System Integrity Protection, you must boot to Recovery OS and run the csrutil(1) command from the Terminal.

Boot to Recovery OS by restarting your machine and holding down the Command and R keys at startup. Launch Terminal from the Utilities menu. Enter the following command: $ csrutil enable

After enabling or disabling System Integrity Protection on a machine, a reboot is required.

Unfortunately you can no longer chown /usr/local in High Sierra. A workaround is to sudo mkdir /usr/local/include and /usr/local/Frameworks if they don't exist, and

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

Thanks to ilovezfs for this simple workaround and for the amazing homebrew!

if you are using zsh because you come from bash you might have to change your $PATH. you should add export PATH=$HOME/bin:/usr/local/bin:$PATH in .zshrc

then it should work, this problem resolved in my mac by this way.