macOS High Sierra(10.13.6)解决"Error: Running Homebrew as root is extremely dangerous and no longer supported."

macOS High Sierra(10.13.6)版本上,使用Homebrew安装python2的时候出现如下问题:

$ brew install python2
Warning: python@2 2.7.15_1 is already installed, it's just not linked
You can use `brew link python@2` to link this version.

$ brew link python@2
Linking /usr/local/Cellar/python@2/2.7.15_1... Error: Permission denied @ dir_s_mkdir - /usr/local/Frameworks

$ sudo brew link python@2
Password:
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.

网上的解决方法是把整个/usr/local的所有者修改为当前用户,但是新版本的macOS High Sierra(10.13.6)已经不支持这样操作了,如下:

$ sudo chown -R `whoami` /usr/local
chown: /usr/local: Operation not permitted

那么解决方法如下:

$ sudo chown -R `whoami` /usr/local/Homebrew/

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

$ sudo mkdir /usr/local/Frameworks

$ sudo chown -R `whoami` /usr/local/Frameworks/

完成上面的操作后,我们可以看到已经能成功操作了:

$ brew link python@2
Linking /usr/local/Cellar/python@2/2.7.15_1... 5 symlinks created

#如果曾经安装过pip可能导致pip被链接到系统的python版本,可是系统目录上各种无权限,因此我们移除已经安装的pip,重新链接pip到brew安装的python

$ sudo rm -rf /usr/local/bin/pip

$ brew reinstall python2

参考链接


发布者

《macOS High Sierra(10.13.6)解决"Error: Running Homebrew as root is extremely dangerous and no longer supported."》上有1条评论

发表回复

您的电子邮箱地址不会被公开。 必填项已用 * 标注