Software⏱️ 2 min read📅 2026-05-31

How to Fix: Unable to install gem - Failed to build gem native extension - cannot load such file -- mkmf (LoadError)

Failed to build gem native extension error in Ruby 1.9.3

Quick Answer: Try updating the system's compiler and re-run the bundle command.

The 'Unable to install gem - Failed to build gem native extension - cannot load such file -- mkmf (LoadError)' error is a common issue encountered when installing gems using Bundler. This error occurs due to the inability of the system to locate or compile the required native extensions for the installed gems.

💡 Why You Are Getting This Error

  • [Cause]

🔧 Proven Troubleshooting Steps

Method 1: Install Required Dependencies

  1. Step 1: Run the command `sudo apt-get install libxml2-dev` to install the required XML development libraries.

Method 2: Compile Native Extensions

  1. Step 1: Run the command `sudo gem install --local /path/to/nokogiri-1.8.0.gem` to compile and install the Nokogiri gem.

💡 Conclusion

By following these steps, you should be able to resolve the 'Unable to install gem - Failed to build gem native extension - cannot load such file -- mkmf (LoadError)' error and successfully install your gems.

Did this fix your problem?

If not, try searching for specific error codes.

🔍 Search Error Database

❓ Frequently Asked Questions