homebrew 无法安装提示不能在根目录下使用

homebrew 无法安装,提示不能在根目录下使用。

Running Homebrew as root is extremely dangerous and no longer supported.
As Homebrew does not drop privileges on installation you would be giving all
build scripts full access to your system.

解决思路就是给当前用户添加目录权限:

如果报错用下面一种方式:

sudo chown -R $(whoami) /usr/local
Error: /usr/local/Cellar is not writable. You should change the
ownership and permissions of /usr/local/Cellar back to your
user account:
  sudo chown -R $(whoami) /usr/local/Cellar
Error: Cannot write to /usr/local/Cellar

我根据提示再次执行命令:

sudo chown -R $(whoami) /usr/local/Cellar
原文地址:https://www.cnblogs.com/sunshine-long/p/8797469.html