安装 cocoapod 时获取 "don't have write permissions"

Getting a "don't have write permissions" when installing cocoapod

我正在尝试为我的 ios 应用设置 google 登录,为此我需要 CocoaPods。但是当像在终端上有自己的网站一样安装它时,我得到这个:

$ sudo gem install cocoapods

[Password: (*Put in my admin password for my macbook*)
ERROR:  While executing gem ... (Gem::FilePermissionError)
You don't have write permissions for the /usr/bin directory.

这是在 Macbook Air 上完成的 运行 High Sierra 10.13.2 (不知道您是否需要该信息,但我之前从未对 cocoapods 或 ruby 做过任何事情)

我也尝试按照这个 并按照 awnser 并安装了 RVM,或者至少我认为我做到了。我只是把这个放在:

ruby -e "$(curl -fsSL 
https://raw.githubusercontent.com/Homebrew/install/master/install)"

好吧,之后我尝试安装 CocoaPods,但仍然得到同样的结果。

您可以尝试以下命令

sudo gem install cocoapods -n /usr/local/bin


问题是 gem install 试图使用 /usr/bin 安装二进制文件,System Integrity Protection 不应触及这些二进制文件。自:

A centerpiece is the protection of system-owned files and directories against modifications by processes without a specific "entitlement", even when executed by the root user or a user with root privileges (sudo)

Sudo 在这种情况下没有任何权力。

因此解决方案使用 -n,从 gem help install 它说:

-n, --bindir DIR Directory where binary files are located

通过这种方式,您将能够将二进制文件移动到更舒适的目的地:/usr/local/bin 代表普通用户可能 运行.

的程序