今天給新買的macbook升級Gem時遇到了錯誤
Installing RubyGems 2.7.7
ERROR: While executing gem ... (Errno::EPERM)
Operation not permitted @ rb_sysopen - /System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/bin/gem
第一直覺我認(rèn)為是這個文件夾沒寫的權(quán)限, 就去修改權(quán)限, 然而
chmod: Unable to change file mode on /System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/bin/gem:
Operation not permitted
堂堂管理員連權(quán)限都沒啦?
網(wǎng)上找解決方案都是幾篇重復(fù)的博客教你修改路徑, 然而我要找到原因啊, 管理員權(quán)限都不好使了還行?
OS X El Capitan v10.11中找到了原因
System Integrity Protection
A new security policy that applies to every running process, including privileged code and code that runs out of the sandbox. The policy extends additional protections to components on disk and at run-time, only allowing system binaries to be modified by the system installer and software updates. Code injection and runtime attachments to system binaries are no longer permitted.
意思就是不能對系統(tǒng)文件進(jìn)行操作了.
所以知道了Operation not permitted的原因, 就知道怎么做了.
一,修改目錄
SIP 讓 /usr/bin 只讀了, 但是 /usr/local 是可讀可寫的, 將安裝目錄修改了.
二,關(guān)閉SIP(不推薦)
如果不想改目錄的話, 只能關(guān)了SIP, 在終端里輸入
csrutil disable
reboot
想要重新打開的話用enable.
這種方法非常不推薦, 相當(dāng)于自己關(guān)了一層防火墻.