我试图使用gem install mygem或使用gem update——system更新RubyGems安装一个gem,它失败了,错误如下:

ERROR:  While executing gem ... (Gem::FilePermissionError)
You don't have write permissions for the /Library/Ruby/Gems/2.0.0 directory.

有人知道怎么解决这个问题吗?


当前回答

对我来说,问题是由于使用rbenv,忘记全局设置正确的版本。

所以我必须用rbenv global xxx来设置它

在我的情况下,我安装了2.0.0-p247,所以我必须发出命令:

rbenv global 2.0.0-p247
rbenv rehash

然后一切都运转正常。

其他回答

我用它工作。

几年前

有两种路由:使用rbenv或RVM。下面是这两种食物的食谱。在此之前,您可能希望关闭gem本地文档的安装。

echo "gem: --no-ri --no-rdoc" >> ~/.gemrc

然后:

安装rbenv

安装ruby-build

运行:

rbenv install 2.1.2 (or whatever version you prefer)
rbenv global 2.1.2
gem update --system

这将在本地目录中安装gem系统的最新版本。这意味着您不会干扰系统配置。如果您正在问这个问题,那么您不应该破坏系统安全性,并且您将花费更长的时间来了解可能遇到的问题,而不仅仅是找到一种简单的方法来避免您开始时遇到的问题。了解更多关于操作系统和编程的知识后,再学习InfoSec。

使用'RVM'替代:

rvm install 2.1.2
rvm use 2.1.2
gem update --system

这有同样的结果,您最终得到的是一个本地Ruby和Gem系统,它不会影响系统版本。不需要Homebrew,也不需要覆盖系统库等等。

我需要做一个rbenv rehash,这样它就会指向我的本地Gem库。

看起来您已经让您的gem管理器指向系统库,因此,与其混淆权限,不如为您的管理器执行等效的“rehash”以获得指向本地的内容。

尝试添加——user-install而不是使用sudo:

gem install mygem --user-install

该错误的原因是您没有以root用户登录终端。

如果你已经在终端类型的mac上启用了根用户

$ su

如果您没有root用户,您需要使用以下步骤启用它

From the Apple menu choose System Preferences…. From the View menu choose Users & Groups. Click the lock and authenticate as an administrator account. Click Login Options…. Click the “Edit…” or “Join…” button at the bottom right. Click the “Open Directory Utility…” button. Click the lock in the Directory Utility window. Enter an administrator account name and password, then click OK. Choose Enable Root User from the Edit menu. Enter the root password you wish to use in both the Password and Verify fields, then click OK.

更多内容请登录http://support.apple.com/kb/ht1528

在被困了几个小时后,至少它对我有用。