/Library:以 root 用户身份登录时不允许进行操作

/Library:以 root 用户身份登录时不允许进行操作

我正在尝试在 El Capitan 上安装 Jekyll,但是我确实收到了权限错误,如下所示。我以 root 用户身份登录。

Linards:~ Berzins$ sudo gem install jekyll
Password:
Ignoring psych-2.0.15 because its extensions are not built.  Try: gem pristine psych --version 2.0.15
Ignoring json-1.8.3 because its extensions are not built.  Try: gem pristine json --version 1.8.3
Fetching: jekyll-3.1.6.gem (100%)
ERROR:  While exexcuting gem ... (Errno::EPERM)
    Operation not permitted - /usr/bin/jekyll
Linards:~ Berzins$ gem pristine psych --version 2.0.15
ERROR:  While executing gem ... (Gem::FilePermissionError)
    You don't have write permissions for the /Library/Ruby/Gems/2.0.0 directory.
Linards:~ Berzins$ ls -l
total 8
drwxr-xr-x  94 Berzins  staff  3196 27 Mar 19:08 Applications
drwx------+ 34 Berzins  staff  1156 26 Jul 22:41 Desktop
drwx------+ 16 Berzins  staff   544  7 Jul 21:58 Documents
drwx------+ 12 Berzins  staff   408 23 Jul 20:58 Downloads
drwx------@ 36 Berzins  staff  1224 26 Jan  2015 Google Drive
drwx------@ 60 Berzins  staff  2040  7 Jul 21:58 Library
-rw-r--r--@  1 Berzins  staff   724  8 Nov  2014 Linards Berzins.downsizelicense
drwx------+  3 Berzins  staff   102 25 Aug  2014 Movies
drwx------+  7 Berzins  staff   238 13 Feb 22:30 Music
drwx------+ 20 Berzins  staff   680 16 Jul 21:03 Pictures
drwxr-xr-x+  6 Berzins  staff   204 23 Sep  2015 Public
drwxr-xr-x   5 Berzins  staff   170  9 Apr 20:53 WebstormProjects
drwxr-xr-x   2 Berzins  staff    68 18 Nov  2015 node_modules
drwxr-xr-x   4 Berzins  staff   136 19 May 21:55 sites
drwxr-xr-x  25 Berzins  staff   850 30 Sep  2015 veltaberzina.com
drwxr-xr-x   6 Berzins  staff   204 18 Nov  2015 version_control
Linards:~ Berzins$ chmod 755 Library
Linards:~ Berzins$ sudo chmod 777 /Library
Password:
chmod: Unable to change file mode on /Library: Operation not permitted

任何建议表示赞赏。

更新:在建议的命令之后 - sudo chflags -R nouchg /Libraryls -le /得到输出:

Linards:~ Berzins$ ls -le /
total 61
drwxrwxr-x+ 108 root     admin  3672 26 Jul 22:53 Applications
 0: group:everyone deny delete
drwxr-xr-x   62 root     wheel  2108  1 May 18:43 Library
drwxr-xr-x@   2 root     wheel    68  1 May 18:34 Network
drwxr-xr-x@   4 root     wheel   136  1 May 18:29 System
 0: group:everyone deny delete
lrwxr-xr-x    1 root     wheel    49 25 Aug  2014 User Information -> /Library/Documentation/User Information.localized
drwxr-xr-x    6 root     admin   204 20 Jun 09:20 Users
drwxrwxrwt@   5 root     admin   170 26 Jul 23:50 Volumes
 0: group:everyone deny add_file,add_subdirectory,directory_inherit,only_inherit
drwxr-xr-x@  39 root     wheel  1326 12 Mar 08:08 bin
drwxrwxr-t@   2 root     admin    68  1 May 18:34 cores
dr-xr-xr-x    3 root     wheel  4316 29 May 11:59 dev
lrwxr-xr-x@   1 root     wheel    11  1 May 18:32 etc -> private/etc
dr-xr-xr-x    2 root     wheel     1 23 Jul 21:03 home
-rw-r--r--@   1 root     wheel   313  2 Aug  2015 installer.failurerequests
dr-xr-xr-x    2 root     wheel     1 23 Jul 21:03 net
drwxr-xr-x@   6 root     wheel   204  1 May 18:34 private
drwxr-xr-x@  59 root     wheel  2006  1 May 18:32 sbin
-rw-rw-rw-    1 Berzins  wheel   586 25 Jul 21:46 sockets.log
lrwxr-xr-x@   1 root     wheel    11  1 May 18:32 tmp -> private/tmp
drwxr-xr-x@  12 root     wheel   308  1 May 18:43 usr
lrwxr-xr-x@   1 root     wheel    11  1 May 18:32 var -> private/var

答案1

Mac OS X 的最新版本具有所谓的系统完整性保护,又名“SIP”,又名“Rootless”。它基本上使文件系统的某些部分只读大家,包括根。您可能已经遇到过这一点。

目的是防止错误和恶意软件修改您的基本操作系统。请参阅/System/Library/Sandbox/rootless.conf参考资料 以获得受 SIP 保护的目录列表。

/usr/local如果可以的话,最简单的解决方案是安装 Jekyll 。

答案2

先决条件

  • Xcode(从 Mac AppStore 下载)
  • Xcode 命令行工具(sudo xcode-select --install或“首选项 → 下载 → 组件”)
  • Ruby(对于 Jekyll 3 为 2 或更高版本)
  • Python 2.7(适用于 Jekyll 2 及更早版本)

ACL 和不可变标志

如果安装了所有先决条件后,您无法下载杰基尔,您可能需要取消设置不可变标志或取消设置 ACL(访问控制列表)。

要显示与文件关联的标志和 ACL,请使用:

$ ls -lOe

/* -e option is used to print ACL, and -O option to show flags */

要取消设置标志,您应该这样做:(例如取消设置uchg您可能需要取消设置的标志)

sudo chflags nouchg /yourDirectory

要删除与文件关联的 ACL,请使用:

chmod -RN /yourDirectory

+使用它后,您将不再在目录末尾看到加号。-R用于更改以文件为根的文件层次结构的模式,而不仅仅是文件本身。

请注意,有时要取消设置某些标志或清除 ACL,系统应处于单用户模式。要启动进入单用户模式,请重新启动 Mac 并同时按住这些⌘+S键,直到看到屏幕上出现白色文本。一旦启动过程完成并且您root#在屏幕上看到,您就可以开始使用终端。

请注意,您不需要取消设置sunlnk标志。

同时,更新操作系统后将重新设置默认配置。所以不用担心,但我建议您在使用命令之前阅读手册页。

最后一步:安装 Jekyll

要安装 Jekyll,请使用:

sudo gem install jekyll

如果您遇到更多问题,请检查Jekyll 文档

相关内容