brew update usr/local must be wrtable

经历描述

  在Mac上要安装telnet工具,然后执行了 brew install telnet,得到提示需要执行 brew update。

在执行brew update的时候,又提示 /usr/local must be wrtable! 

然后再网上各种查找,试了很多方式无果,大多数的解决方案都是修改 /usr/local  文件的属性,执行如下命令

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

得到的提示是 Operation not permitted

又经过一通的查找发现苹果在新版的OS中引入了rootless机制(SIP),SIP的目的是为了防止应用程序获取root权限,进而修改

系统的关键文件。而这几个关键文件目录包括:

  /system

  /usr

  /bin

  /sbin

  与安装的一些应用及App Store、Itures等

既然默认OS开启了rootless,那我们只要关闭该功能即可,就是进入系统的恢复模式,执行关闭命令。操作如下:

1) 重启电脑,按着Command+R键,再出现选择时,选择Recoverty,并选择相应的语言,进入恢复模式

2) 菜单找到实用程序(Utilities),在里面找到终端(Terminal),并执行

csrutil disable  来关闭SIP

当然针对brew update这个问题,可以通过先卸载homebrew,然后再重新安装来解决,操作如下:
卸载
/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/uninstall)"
重装
/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

原文地址:https://www.cnblogs.com/oneheart/p/12972897.html