21

I have created new rails app and try to run bundle install it shows this error,

Gem::Ext::BuildError: ERROR: Failed to build gem native extension.
current directory: /var/lib/gems/2.3.0/gems/json-1.8.6/ext/json/ext/generator/usr/bin/ruby2.3 -r ./siteconf20170704-11395-12tpg5u.rb extconf.rb
mkmf.rb can't find header files for ruby at /usr/lib/ruby/include/ruby.h
extconf failed, exit code 1

Gem files will remain installed in /var/lib/gems/2.3.0/gems/json-1.8.6 for inspection.
Results logged to /var/lib/gems/2.3.0/extensions/x86_64-linux/2.3.0/json-1.8.6/gem_make.out

An error occurred while installing json (1.8.6), and Bundler cannot continue.
Make sure that `gem install json -v '1.8.6'` succeeds before bundling

Kindly send me some suggestions,Thanks in Advance.

2
  • what happens when you do gem install json -v '1.8.6'
    – Sajin
    Jul 4, 2017 at 9:27
  • 2
    It shows this error ERROR: Failed to build gem native extension. Jul 4, 2017 at 9:37

3 Answers 3

23

If you have a Mac or Linux machine try the following command:

sudo apt-get install ruby-dev

If that fails, what is your output for:

gem install json -v '1.8.6'

(please copy and paste all the output).

Similar issue

I'm not sure what will fix it for Mac, but people had positive experiences with brew install ruby.

5
  • 1
    apt-get doesn't work in Mac out of the box. Maybe add brew version of this too? Apr 15, 2019 at 9:12
  • @rentedrainbow I can't replicate this on my Mac, do you know what you need to install with brew? Apr 18, 2019 at 10:24
  • 3
    Yes, did brew install ruby and then it worked again on macOS.
    – appsunited
    Oct 14, 2019 at 10:42
  • I didn't encounter that on my Mac but I posted @appsunited's suggestion just in case it will help people. Dec 19, 2019 at 9:43
  • this is the error l am getting: fatal error: 'ruby/config.h' file not found #include "ruby/config.h"
    – CanCoder
    Jan 5, 2021 at 16:42
3

If anyone facing this error with Mac OS Big Sur, please update the ruby version to atleast 2.7. I am using rvm to resolve this issue.

0

First checked the ruby version and rvm list if rvm not install then install rvm

3

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.