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

最近在新Mac下面安装node,没想到遇到这个问题,Mac版本是10.12。图片描述

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,依然是同样报错,我查看了brew的版本,和我之前的Mac不太一样。
如下
图片描述

阅读 79.1k
8 个回答

提示你不要在root权限下使用brew,那你就不要加sudo了

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

/use/local的owner換成自己,就有write權限了

whoami就是一個命令,會echo當前登錄用戶的名字。當然你知道自己的用戶名,比如jack,就直接

sudo chown -R jack /usr/local

也可以

修改過權限之後,就直接跑

brew install node

不需要再用sudo,因為當前用戶已經有權限寫入/usr/local了
或者你用

ls -ld /usr/local

確認一下這個目錄的owner是否已改到自己

遇到同一个问题,新买的MacBook pro,安装失败
error: RPC failed; curl 56 SSLRead() return error -9806/s
fatal: The remote end hung up unexpectedly
fatal: early EOF
fatal: index-pack failed
Error: Failure while executing: git clone https://github.com/Homebrew/h... /usr/local/Homebrew/Library/Taps/homebrew/homebrew-core --depth=1
Error: Failure while executing: /usr/local/bin/brew tap homebrew/core
Failed during: /usr/local/bin/brew update --force

也是mac,做了以下操作就可以啦。
Error: 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.
➜ ~ brew install Graphviz
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
fatal: could not create leading directories of '/usr/local/Library/Taps/homebrew/homebrew-core': Permission denied
Error: Failure while executing: git clone https://github.com/Homebrew/h... /usr/local/Library/Taps/homebrew/homebrew-core --depth=1 -q
Error: Failure while executing: /usr/local/bin/brew tap homebrew/core -q
➜ ~ sudo mkdir -p /usr/local/Library/Taps/homebrew/homebrew-core

➜ ~ brew install Graphviz
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
Error: No available formula with the name "graphviz"

新手上路,请多包涵

sudo -i 你可以试试先开启超级权限,然后直接安装看看行不行就不要加sudo了

新手上路,请多包涵

Could not symlink include/node
/usr/local/include is not writable.
我这里提示这个不能写,我直接用finder去文件夹里面创建了。

新手上路,请多包涵

直接去改/opt/homebrew/Library/Homebrew里的brew.sh文件。(你也有可能在其他位置,自己找一找)
在 check-run-command-as-root() 方法里面直接return掉。
原理是他在这个方法判断id是否为0(root的id为0),来知道你是否是root执行的。
直接return掉就一切OK了,虽然不优雅,但有效。

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
宣传栏