我试图使用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 cocoapods——pre——user

其他回答

sudo chown -R $USER /Library/Ruby/Gems/

检查你的Ruby版本是否正确。如果不是,那就改变它。

这对我来说很管用:

$ rbenv global 1.9.3-p547
$ gem update --system

安装gem或更新RubyGems失败,出现权限错误,然后输入此命令

sudo gem install cocoapods

你需要修正你的路径。

要确定此修复是否有效,请运行以下命令:

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

我用它工作。

几年前