我试图使用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.
有人知道怎么解决这个问题吗?
我试图使用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
然后一切都运转正常。
其他回答
检查你的Ruby版本是否正确。如果不是,那就改变它。
这对我来说很管用:
$ rbenv global 1.9.3-p547
$ gem update --system
该错误的原因是您没有以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
在被困了几个小时后,至少它对我有用。
您可以更改GEM_HOME。您还在您的主目录下有一个gem文件夹来检查它的使用
$ gem env
结果如下。不相关的部分省略。
...
- GEM PATHS:
- /Users/xxx/.gem/ruby/2.6.0
- /Library/Ruby/Gems/2.6.0
- /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/gems/2.6.0
...
你可以使用你的/Users/xxx/.gem/ruby/2.6.0文件夹。
vim ~/.bash_profile
添加以下行
export GEM_HOME=~/.gem/ruby/2.6.0/
之后你就可以使用了
source ~/.bash_profile
你需要修正你的路径。
要确定此修复是否有效,请运行以下命令:
which gem
这应该会输出一个你没有权限的目录:
/usr/bin/gem
要修复此问题,请执行以下步骤:
Determine the path you need to copy to your profile: rbenv init - The first line of the output is the line you need to copy over to your profile: export PATH="/Users/justin/.rbenv/shims:${PATH}" #path that needs to be copied source "/usr/local/Cellar/rbenv/0.4.0/libexec/../completions/rbenv.zsh" rbenv rehash 2>/dev/null rbenv() { typeset command command="$1" if [ "$#" -gt 0 ]; then shift fi case "$command" in rehash|shell) eval `rbenv "sh-$command" "$@"`;; *) command rbenv "$command" "$@";; esac } Copy the path to your profile and save it. Reload your profile (source ~/.zshenv for me). Run rbenv rehash.
现在当你运行哪个gem时,你应该得到一个你有权限的本地路径:
/Users/justin/.rbenv/shims/gem
您确实应该使用Ruby版本管理器。
在执行gem更新命令时,正确使用它可以防止并解决权限问题。
我推荐rbenv。
但是,即使使用Ruby版本管理器,仍然可能会得到相同的错误消息。
如果这样做,并且使用的是rbenv,只需验证~/。rbenv/shims目录在系统Ruby路径之前。
$ echo $PATH将显示加载路径的顺序。
如果您发现shims目录位于系统Ruby bin目录之后,则编辑~/。export PATH=$HOME/.rbenv/shims:$PATH . bashrc文件,并将其作为最后一个导出PATH命令
$ ruby -v显示你正在使用的ruby版本
这表明我目前使用的是Ruby的系统版本(通常不太好)
$ ruby -v
ruby 1.8.7 (2012-02-08 patchlevel 358) [universal-darwin12.0]
$ rbenv global 1.9.3-p448将我切换到更新的预安装版本(参见下面的参考资料)。
这表明我正在使用一个更新版本的Ruby(这可能不会导致Gem::FilePermissionError)
$ ruby -v
ruby 1.9.3p448 (2013-06-27 revision 41675) [x86_64-darwin12.4.0]
通常不需要在gem命令前加上sudo。如果您觉得需要这样做,则可能是配置错误。
关于rbenv的详细信息请参见:
https://github.com/sstephenson/rbenv http://robots.thoughtbot.com/post/47273164981/using-rbenv-to-manage-rubies-and-gems