rails 5.0.0 安装 "nio4r" 时:无法构建 gem 本机扩展

rails 5.0.0 when installing "nio4r" : Failed to build gem native extension

这是日志:http://pastebin.com/CAgur9xd

Installing nio4r 1.2.1 with native extensions

Gem::Ext::BuildError: ERROR: Failed to build gem native extension.

    C:/RailsInstaller/Ruby2.2.0/bin/ruby.exe -r ./siteconf20160720-8272-c88sgk.rb extconf.rb --with-cflags=-std=c99
checking for unistd.h... *** extconf.rb failed ***
Could not create Makefile due to some reason, probably lack of necessary
libraries and/or headers.  Check the mkmf.log file for more details.  You may
need configuration options.

Provided configuration options:
        --with-opt-dir
        --without-opt-dir
        --with-opt-include
        --without-opt-include=${opt-dir}/include
        --with-opt-lib
        --without-opt-lib=${opt-dir}/lib
        --with-make-prog
        --without-make-prog
        --srcdir=.
        --curdir
        --ruby=C:/RailsInstaller/Ruby2.2.0/bin/$(RUBY_BASE_NAME)
C:/RailsInstaller/Ruby2.2.0/lib/ruby/2.2.0/mkmf.rb:456:in `try_do': The compiler failed to generate an executable file. (RuntimeError)
You have to install development tools first.
        from C:/RailsInstaller/Ruby2.2.0/lib/ruby/2.2.0/mkmf.rb:587:in `try_cpp'
         from C:/RailsInstaller/Ruby2.2.0/lib/ruby/2.2.0/mkmf.rb:1060:in `block in have_header'
        from C:/RailsInstaller/Ruby2.2.0/lib/ruby/2.2.0/mkmf.rb:911:in `block in checking_for'
        from C:/RailsInstaller/Ruby2.2.0/lib/ruby/2.2.0/mkmf.rb:351:in `block (2 levels) in postpone'
        from C:/RailsInstaller/Ruby2.2.0/lib/ruby/2.2.0/mkmf.rb:321:in `open'
        from C:/RailsInstaller/Ruby2.2.0/lib/ruby/2.2.0/mkmf.rb:351:in `block in postpone'
        from C:/RailsInstaller/Ruby2.2.0/lib/ruby/2.2.0/mkmf.rb:321:in `open'
        from C:/RailsInstaller/Ruby2.2.0/lib/ruby/2.2.0/mkmf.rb:347:in `postpone'
        from C:/RailsInstaller/Ruby2.2.0/lib/ruby/2.2.0/mkmf.rb:910:in `checking_for'
        from C:/RailsInstaller/Ruby2.2.0/lib/ruby/2.2.0/mkmf.rb:1059:in `have_header'
        from extconf.rb:3:in `<main>'

extconf failed, exit code 1

安装捆绑包时 returns(从日志中的第 117 行开始):

Installing nio4r 1.2.1 with native extensions
Gem::Ext::BuildError: ERROR: Failed to build gem native extension.

因此无法安装捆绑包。它 returns 最后 :

An error occurred while installing nio4r (1.2.1), and Bundler cannot continue.
Make sure that `gem install nio4r -v '1.2.1'` succeeds before bundling.

注意:我已经尝试了其他问题的解决方案,但还是一样。 如果可以手动安装 "nio4r",请告诉我如何安装。

删除 Gemfile.lock 和 运行 捆绑安装命令

引用您的日志输出:

The compiler failed to generate an executable file. (RuntimeError) You have to install development tools first.

在 windows 上,您需要 install the DevKit 才能编译 gems。

我在尝试将我的 Rails 升级到 V5.0.0 时遇到了同样的问题,我按照此说明进行操作并且运行良好。在此处阅读 "Install the Ruby DevKit" 部分 >> http://jekyll-windows.juthilo.com/1-ruby-and-devkit/

我在设置 rails 时也遇到了这个问题。 (寻找 php 的替代品)。

  • 我意识到我安装了 x86 ruby 和 x64 Devkit,所以我首先下载了 x64 ruby 我安装并卸载了 x86 版本。我确保我的路径变量设置正确。
  • 然后我使用此页面上的说明安装了 devkit http://rubyonwindowsguides.github.io/book/ch02-04.html
  • 我终于安装了 rails 并且这次运行正常,没有出现错误

希望对您有所帮助

我儿子帮我解决了这个问题。问题是我先安装了 Ruby,然后是 Rails 安装程序。所以我不得不卸载 Ruby 并仅使用 Rails 安装程序重新安装。

我遇到了类似的问题,运行使用这个命令解决了我的问题。

bundle config build.nio4r --with-cflags="-std=c99"

现在可以运行 bundle install 之后成功了。

Fedora 64 位解决方案

sudo dnf install redhat-rpm-config

在 Ubuntu 16.04 上遇到了同样的问题。 我做了什么来解决这个问题:

删除 Gemfile.lock : sudo rm Gemfile.lock 已安装 Ruby-开发:

sudo apt-add-repository ppa:brightbox/ruby-ng sudo apt-get 更新 sudo apt-get install ruby​​2.4-dev

重要的一步:重启!

如果您使用 Windows 并使用版本高于或等于 2.4 的 Ruby 安装程序安装 ruby,那么您不应从 Ruby 安装程序网站安装 DevKit,并且仅使用 Ruby 之后安装的 'msys64' 和 Ruby 安装程序(确保键入数字 3 以安装 msys 和 mingw)。从 PATH 环境变量中删除 devkit 目录及其路径,因此当 rubygems 将尝试安装 nio4r 并调用 C 编译器时,它将调用 msys 的。 阅读此处 https://rubyinstaller.org/2017/05/25/rubyinstaller-2.4.1-1-released.html,了解有关 RubyInstaller

中 MSYS2 和 DevKit 的更多信息

这可能是相关的:GCC compilation error when installing Nokogiri

I found a error. i had a 2 gcc versions installed on my system and I just run brew unlink gcc and that solved the problem.

这也是我的情况。 benw unlink gcc 成功了