Windows 7 64位系统下无法安装ffi gem的问题求助
Hey there! I see you're just getting started with Cucumber and Ruby, and hit a snag installing the ffi gem—let's get this sorted out for you.
What's causing the error?
The core issue here is a version compatibility mismatch:
- The error message tells you the last
ffiversion that supports your current RubyGems setup is 1.9.18, but ffi 1.9.18 requires Ruby versions between 2.0 and 2.4.x (strictly less than 2.5). - Your current Ruby version is 2.5.0, which falls outside that range—so installing 1.9.18 fails, and trying to install the latest
ffiwithout specifying a version might be pulling up that incompatible old version by default for some reason.
Two ways to fix this:
1. Install a newer, Ruby 2.5-compatible version of ffi
Good news: Later versions of ffi (starting from 1.10.0) added support for Ruby 2.5.0. You can bypass the old incompatible version by explicitly installing a compatible one:
- Run this command in your terminal:
gem install ffi -v ">=1.10.0" - If you're using a Gemfile for your project, update the line for
ffito:
Then rungem 'ffi', '>=1.10.0'bundle installto sync your dependencies.
2. Downgrade your Ruby version (if you need the old ffi version)
If your project has strict dependencies that require ffi 1.9.18, you'll need to switch to a Ruby version that works with it (2.0–2.4.x). Using a Ruby version manager like rbenv or RVM makes this easy:
- For rbenv:
- Install Ruby 2.4.10 (the latest patch release of 2.4.x):
rbenv install 2.4.10 - Set this version as the default for your project:
rbenv local 2.4.10 - Now install the required ffi version:
gem install ffi -v 1.9.18
- Install Ruby 2.4.10 (the latest patch release of 2.4.x):
Recommendation
Unless you have a specific reason to stick with ffi 1.9.18, go with option 1—it lets you keep your current Ruby 2.5.0 and get a fully supported version of ffi.
内容的提问来源于stack exchange,提问作者NateG

