Rails 5.2.0执行bundle install时Gem原生扩展编译失败求助
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:
- Extract it to a path with no spaces (e.g.,
C:/DevKit— avoidProgram Files!) - 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

