You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Windows10 x64安装Rails失败:gem原生扩展构建失败求助

Fixing "failed to build gem native extension" When Installing Rails on Windows 10 x64

Hey there! That failed to build gem native extension error is a classic gotcha on Windows when setting up Rails—most of the time it’s because your system is missing the tools needed to compile Ruby’s native extensions. Let’s walk through the most reliable fixes:

1. Install the RubyInstaller Development Kit (DevKit)

Ruby gems with native components need a C compiler and build tools to work, which Windows doesn’t include by default. The RubyInstaller DevKit is the official solution for this:

  • First, check your Ruby version by running ruby -v in Command Prompt or PowerShell. Note down the version (e.g., 3.2.2) and architecture (x64).
  • Download the matching DevKit that corresponds to your Ruby version from the official RubyInstaller resources. For newer Ruby versions (3.0+), there’s often an "Installer with DevKit" option you can use if you want to re-install Ruby with the tools included.
  • Extract the DevKit to a permanent folder (e.g., C:\RubyDevKit—avoid spaces in the path!).
  • Open a command line, navigate to the DevKit folder, and run:
    ruby dk.rb init
    ruby dk.rb install
    
    This links the DevKit to your Ruby installation.

2. Reinstall Rails with the Updated Environment

Once the DevKit is set up, close and re-open your command line to refresh the environment variables. Then run:

gem install rails

This should now have the tools needed to compile any native extensions required by Rails and its dependencies.

3. If the Error Persists: Check the Detailed Log

The generic "failed to build gem native extension" message usually hides a specific issue (like missing OpenSSL libraries or a problem with a particular gem). Look further up in the error output for lines like:

ERROR: Failed to build gem native extension for nokogiri-1.15.4

Once you identify the problematic gem, you can troubleshoot it specifically. For example, if it’s nokogiri, you might need to install precompiled binaries by running:

gem install nokogiri --use-system-libraries

4. Alternative: Use Windows Subsystem for Linux (WSL)

If you’re planning to do serious Rails development, WSL is a game-changer. It lets you run a Linux environment directly on Windows, where Ruby and Rails work much more smoothly without native extension headaches. Here’s the quick setup:

  • Enable WSL in Windows Settings (search for "Turn Windows features on or off" and check "Windows Subsystem for Linux").
  • Install a Linux distribution (like Ubuntu) from the Microsoft Store.
  • Open your Linux terminal, update packages with sudo apt update && sudo apt upgrade, then install Ruby, Gem, and Rails using the Linux package manager or tools like rbenv/rvm.

内容的提问来源于stack exchange,提问作者Achiel Volckaert

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.19 07:40:19