You don't have write permissions for the /usr/bin directory.

You don't have write permissions for the /usr/bin directory.

安装macOS High Sierra 版本10.13.3后安装cocoapods卡住:

HOLOTHURIAN:~ sharktop$ sudo gem uninstall cocoapods
Remove executables:
pod, sandbox-pod


in addition to the gem? [Yn]  y
ERROR:  While executing gem ... (Gem::FilePermissionError)

    You don't have write permissions for the /usr/bin directory.

经过一系列查证并亲自试验,是关于Apple在OS X El Capitan中全面启用了名为System Integrity Protection (SIP)的系统完整性保护技术。受此影响,大部分系统文件即使在root用户下也无法直接进行修改。

需要关闭SIP保护技术

  1. 重启Mac
  2. 按住command+r(Recovery模式)
  3. 选择实用工具菜单中的命令行(terminal/终端)
  4. 输入csrutil disable并回车
  5. 再次重启mac
  6. 进入终端执行sudo gem update –system

    更新完毕后你可以进行相关的gem命令操作。不过此时你的电脑处于SIP的关闭状态,对于系统来说可能是不安全的,所以这种操作需要谨慎。 
    也可以按照上述步骤,使用csrutil enable指令重新打开你的SIP。

    在终端中可以查看SIP状态、具体操作可能就得recovery模式下了。

    $csrutil status 状态查询

    $csrutil enable 开启

    $csrutil disable 禁用