Error: Operation not permitted on MacOS while installing the Homebrew
Today, I faced a strange error while updating (Installing and Installing the homebrew again) on my Mac. I spent almost 4-5 hours. Every time it was giving me this error: chown: /usr/local/Homebrew/Library/Homebrew/brew.sh: Operation not permitted.
I was already logged in with the Admin account but still, I was facing the same issue. I tried to uninstall the brew using this command: /usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/uninstall)". And re-install it again with /usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)" But unfortunately I was not getting rid of form this error. I reboot my system many times but, no luck.
Finally, I fixed it with the following steps:
1. I uninstall brew with the same uninstallation command as:
/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/uninstall)".2. I removed the Homebrew directory by the following command:
sudo rm -rf /usr/local/Homebrew/. Actually, this was the evil in the whole story3. Now Using the following command to install brew worked like a charm.
/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)".
So basically the issue was with the Homebrew folder, it was there even uninstalling the brew. And when I was trying to install it again it was not letting me overwrite it.
sudo rm -rf /usr/local/Homebrew/ made my day. :)