安装 rails 时出错:nokogiri 需要 Ruby 版本 < 2.4,>= 2.1.0

Error Installing rails: nokogiri requires Ruby version < 2.4, >= 2.1.0

我在 'Start Command Prompt with Ruby(this is just like command prompt that got installed with ruby)' 的 windows 8.1 上安装 ruby 2.4.1p111 后尝试安装 rails。

我使用命令 gem install rails 并在暂停几秒钟后将问题的标题作为错误抛出。

我尝试了命令 gem install nokogiri -v 1.7.1,它抛出了同样的错误。

如果我运行 gem list,它根本不会列出nokogiri。

我阅读了一个可能的解决方案。 使用一些命令 gem 'nokogiri', '~> 1.6.8' 在 gem Gemfile 中更改 nokogiri 版本。我不知道这是否适用于我安装的 rails 版本。如果这是解决方案,我该如何实施?

如何纠正此错误并安装 rails?

显然 Nokogiri 与 Ruby 2.4+ 的兼容性存在问题1,您可以查看报告 here;它将在 Nokogiri 1.8.0 中修复。

在此期间,您可以使用 Ruby 2.3.4,直到 1.8.0 版本发布。

I don't know if that even applies to the version of rails I have installed.

不,它不会,因为您将降级 Nokogiri 版本并且不会解决兼容性问题。这适用于 Ruby 版本早于 2.1.0

的用户

1 请注意(正如评论中指出的那样)这 Windows-only 问题。

编辑:

您现在可以更新您的 gemfile:

gem "nokogiri", (RUBY_VERSION >= "2.1" ? "~> 1.8" : "~> 1.6.8")