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

Rails 5.2.0执行bundle install时Gem原生扩展编译失败求助

Fixing Gem Native Extension Build Failures During bundle install for Ruby 2.2 Rails Apps

Hey, let's sort out that native extension build error you're running into with bundle install on your Ruby 2.2 Rails app. Looking at your error logs, the core issues are mismatched bitness between Ruby and your build tools (plus missing or misconfigured DevKit on Windows) — which is super common when dealing with older Ruby versions like 2.2. Here's how to fix it:

1. Match Ruby and DevKit Bitness

Your Ruby is installed at C:/Ruby22 — first confirm if it's 32-bit or 64-bit:

  • If the folder name doesn't have x64, it's 32-bit. Grab the 32-bit DevKit-mingw64-32 (specifically version 4.7.2, since newer DevKits don't play nice with Ruby 2.2)
  • If it's 64-bit (folder has x64), get the 64-bit DevKit-mingw64-64 (also version 4.7.2)

2. Set Up DevKit Correctly

Once you've downloaded the right DevKit:

  1. Extract it to a path with no spaces (e.g., C:/DevKit — avoid Program Files!)
  2. Open Command Prompt, navigate to the DevKit folder, and run these commands:
    cd C:/DevKit
    ruby dk.rb init
    ruby dk.rb install
    

This links the DevKit toolchain to your Ruby installation, so bundle knows how to compile native gems.

3. Pin Gem Versions to Ruby 2.2 Compatibility

Ruby 2.2 is pretty old, so many modern gem versions drop support for it. For example, the json gem (which looks like what's failing to compile here) needs an older version. Add this to your Gemfile:

gem 'json', '<= 2.1.0'

Then re-run:

bundle install

4. Clean Up Old Build Caches

Sometimes leftover build files cause issues. Clear them out first:

gem cleanup
rm -rf vendor/bundle # Skip this if you aren't using local bundle caching
bundle install --clean

Quick Extra Checks

  • Make sure you have the Visual C++ 2013 Redistributable installed — Ruby 2.2 relies on this runtime.
  • Double-check that your Ruby and DevKit are installed in paths with no spaces or special characters (this breaks build scripts more often than you'd think!)

Follow these steps, and your bundle install should complete without the native extension errors.

内容的提问来源于stack exchange,提问作者Yogesh Shakya

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.28 10:16:07