安装 rails 失败,"failed to build gem native extension"

installing rails fails, "failed to build gem native extension"

我刚刚在 windows 10 x64 上安装了 rubygem,我检查过它们都已安装。当我尝试安装 rails 时,它在一段时间后失败了。

查看下面的 link 使用的命令

El Administrator: Windows PowerShell 

PS C:\WINDOWS\system32> ruby -v 
ruby 2.4.3p205 (2017-12-14 revision 61247) (x64-mingw32] 
PS C:\WINDOWS\system32> gem --version 2.6.14 PS 
C:\WINDOWS\system32> gem install rails 
Temporarily enhancing PATH for MSYS/MINGW... 
Building native extensions. This could take a while... 
ERROR: Error installing rails: 
       ERROR: Failed to build gem native extension.

    current directory: CuRuby24-x64/lib/ruby/gems/2.4.0/gems/nio4r-2.2.0/ext/nio4r 
C:/Ruby24-x64/bin/ruby.exe -r asiteconf20180211-14528-1um1rd2.rb extconf.rb 

current directory: C:/Ruby24-x64/lib/ruby/gems/2.4.0/gems/nio4r-2.2.0/ext/nio4r 
make "DESTDIR=" clean 
'make' is not recognized as an internal or external command, 
operable program or batch file. 

current directory: C:/Ruby24-x64/lib/ruby/gems/2.4.0/gems/nio4r-2.2.0/ext/nio4r 
make "DESTDIR=" 
'make' is not recognized as an internal or external command, 
operable program or batch file. 

make failed, exit code 1 

Gem files will remain installed in C:/Ruby24-x64/lib/ruby/gems/2.4.0/gems/nio4r-2.2.0 for inspection. 
Results logged to C:/Ruby24-x64/lib/ruby/gems/2.4.0/extensions/x64-mingw32/2.4.0/nio4r-2.2.0/gem_make.out 
PS C:\WINDOWS\system32> 

我使用 wsl 解决了这个问题。安装过程解释 here. I also had to use this 以在 windows 10 build 16299.192(设置 > 系统 > 关于)上启用 wsl。在我安装了所有东西之后,我 运行 sudo apt-get install nodejsgem install rails。在此之后,我可以 运行 演示 (wsl> rails new demo, wsl> cd demo, wsl> rails server).

您需要构建工具来构建本机扩展。

sudo apt-get update
sudo apt-get install build-essential

来源:How do I fix an error with Ruby Gems Installer on WSL?