美文网首页工具相关
[macOS]升级Ruby遇到Errno::EPERM的原因

[macOS]升级Ruby遇到Errno::EPERM的原因

作者: 绿问问 | 来源:发表于2018-09-26 14:45 被阅读0次

    今天给新买的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
    

    第一直觉我认为是这个文件夹没写的权限, 就去修改权限, 然而

    chmod: Unable to change file mode on /System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/bin/gem: 
    Operation not permitted
    

    堂堂管理员连权限都没啦?
    网上找解决方案都是几篇重复的博客教你修改路径, 然而我要找到原因啊, 管理员权限都不好使了还行?
    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.

    意思就是不能对系统文件进行操作了.
    所以知道了Operation not permitted的原因, 就知道怎么做了.

    一,修改目录

    SIP 让 /usr/bin 只读了, 但是 /usr/local 是可读可写的, 将安装目录修改了.

    二,关闭SIP(不推荐)

    如果不想改目录的话, 只能关了SIP, 在终端里输入

    csrutil disable
    reboot 
    

    想要重新打开的话用enable.
    这种方法非常不推荐, 相当于自己关了一层防火墙.

    相关文章

      网友评论

        本文标题:[macOS]升级Ruby遇到Errno::EPERM的原因

        本文链接:https://www.haomeiwen.com/subject/jtwdoftx.html