为什么我会收到“ERROR: While executing gem ... (Gem::FilePermissionError)”错误提示?

4

卸载了RVM 并使用 单用户安装 重新安装,命令如下:

\curl -L https://get.rvm.io | bash -s stable

当我执行bundle时,它会提示:
Enter your password to install the bundled RubyGems to your system:

我尝试使用 "ERROR: While executing gem … (Gem::FilePermissionError)" 中的答案,但并没有解决问题。
然后,在尝试手动安装 gem 时,我遇到了以下问题:
Gem::InstallError: nokogiri requires Ruby version >= 1.9.2.
An error occurred while installing nokogiri (1.6.0), and Bundler cannot continue.
Make sure that `gem install nokogiri -v '1.6.0'` succeeds before bundling.

然后运行 gem install nokogiri -v '1.6.0' 返回:

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

我在Stack Overflow上查看了所有类似的帖子,但它们都没有解决问题。我错过了什么?


1
从您的错误信息中可以看出(nokogiri需要Ruby版本>=1.9.2),您使用的是较旧的Ruby版本。请检查您的Ruby版本。 - cristian
谢谢,那帮了我解决问题!在更新 Ruby 版本后,我不得不手动安装几个 gem。您可以将其写成答案,我会接受它。 - Ava
3个回答

3

我在我的 MacBook 上花了很多时间修复此问题。对我而言,gem update --system 没有起作用。

最后,在 ~/.zshrc 文件中添加以下代码并创建新的 zsh 会话对我起作用。

export GEM_HOME="$HOME/.gem"
export GEM_PATH="$HOME/.gem"

太棒了!就像魔法一样!非常感谢! - Aviram Netanel

3
安装完RVM之后,您仍需要执行以下几个步骤:

  1. Load RVM to the current shell:

    source ~/.rvm/scripts/rvm
    

    Usually this would not be needed if you close and open your terminal again

  2. Install ruby:

    rvm install ruby
    
  3. Use ruby:

    rvm use ruby
    
最后一步非常重要,因为你的错误消息提到了系统 Ruby 而不是由 RVM 控制的 Ruby。

在运行rvm脚本之前,请执行以下命令:\curl -sSL https://get.rvm.io | bash -s stable。 - Hari Narayanan

0
请确保使用此命令更新您的系统rubygems:sudo gem update --system --no-user-installbundler 使用它,而不是您本地版本,您的bundler版本可能与您的系统rubygems不兼容。
这对我有用;)

这解决了我通过rbenv得到的相同错误。谢谢! - deprecated

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接