How Do I Install A Ruby Gem With Native Extensions On Windows?
How Do I Install A Ruby Gem With Native Extensions On Windows?
One of the challenges many Ruby on Windows users have is how to easily use native RubyGems from the community such as the rdiscount or redcloth gems.
Many Window users have seen this error:
Building native extensions. This could take a while...
ERROR: Error installing bson_ext:
ERROR: Failed to build gem native extension.
...
For most gems this isn’t a problem because the extension author has provided a binary gem compatible with the users Ruby environment. In other cases, only the extension source code is available in the gem and the user is expected to have a “sane” environment installed and configured to build and use the native gem.
A “sane” environment typically means a system with make, gcc, sh and similar *nix build tools installed. This expectation of a “sane” build environment is not always true for Windows users and is the primary reason why the DevKit was created. The DevKit, based upon MSYS and MinGW components, is an easy-to-install and easy-to-use solution for quickly setting up a “sane” build environment, enabling you to use most native RubyGems developed by the Ruby community.
Requirements
- Window XP or greater (32 or 64-bit).
- A Ruby installation from RubyInstaller.
Steps involved
- Download and install 7-zip.
- Download the Development Kit and install it in say
c:\devkit. - Open a command window and type
c:. - Change folders by typing
cd devkit. - Type
ruby dk.rb initto generate theconfig.ymlfile to be used later. Your installed Rubies will be listed there (only those installed by a RubyInstaller package are detected at present). This needs to be done only once. - Finally type,
ruby dk.rb installfor DevKit enhance your installed Rubies. This needs to be done only once. - Confirm your Ruby environment is correctly using the DevKit by running:
gem install bson_ext --platform=ruby. It’s crucial that you include the--platform=rubyoption to force RubyGems to build the native gem rather than potentially installing an incorrect binary gem.
That’s it.
Satish Talim is an author and founder of RubyLearning.com and RubyLearning.org where over 35000 participants have learnt Ruby programming from across the globe.

{ 3 comments… read them below or add one }
Thanks to Luis Lavena for pointing out to the Troubleshooting page.
Hello Satish,
Thanks for this, very helpful.
I completed all the steps and it all seemed to work. But I still got “Failed to build gem native extension.”
Alan, did you check out the Troubleshooting page?