Error Occurred while installing 'bundle install' and 'gem install json

Im trying to setup ruby on local and I am running into some issues.

1. When i run ‘bundle install’ , the following error occur

Installing json 2.6.1 with native extensions
Gem::Ext::BuildError: ERROR: Failed to build gem native extension.

fatal error: ‘ruby/config.h’ file not found
#include “ruby/config.h”
^~~~~~~~~~~~~~~
/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/include/ruby-2.6.0/ruby/ruby.h:24:10:
note: did not find header ‘config.h’ in framework ‘ruby’ (loaded from
‘/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/System/Library/Frameworks’)
1 error generated.
make: *** [generator.o] Error 1
make failed, exit code 2
Gem files will remain installed in /Users/**/.gem/gems/json-2.6.1 for inspection.
Results logged to
/Users/****/.gem/extensions/universal-darwin-21/2.6.0/json-2.6.1/gem_make.out

An error occurred while installing json (2.6.1), and Bundler cannot continue.
In Gemfile:
coveralls was resolved to 0.8.23, which depends on
simplecov was resolved to 0.16.1, which depends on
json

==============
2. Then i executed ‘gem install json’, the following error occurred

Building native extensions. This could take a while…
ERROR: Error installing json:
ERROR: Failed to build gem native extension.

1 error generated.
make: *** [generator.o] Error 1
make failed, exit code 2
Gem files will remain installed in /Users/**/.gem/gems/json-2.6.1 for inspection.
Results logged to /Users/****/.gem/extensions/universal-darwin-21/2.6.0/json-2.6.1/gem_make.out

  • I am using macOS 12.2.1
  • ruby 2.6.8p205 (2021-07-07 revision 67951) [universal.x86_64-darwin21]
  • bundler version 2.3.9
  • gem version 3.3.9

Any help would be great.

Thanks

1 Like

This is a very common error. You get this whenever you’re using Linux distributions like Ubuntu, Fedora, and OpenSUSE. They don’t provide you ruby-devel package by default, but the gem you’re using contains native C extensions. Ruby.h provides the Ruby C API. And a lot of gem use that.

To solve the issue, you need to install the ruby-dev package on Ubuntu, or ruby-devel package on Fedora / OpenSUSE. You also need a compiler to compile the code that’s using ruby.h.

Ubuntu:

# apt install gcc build-essential ruby ruby-dev build-essential

Fedora:

# yum install gcc ruby-devel ruby make

OpenSUSE:

# zypper install gcc ruby ruby-devel make

All the # means as a root user. In most cases, sudo or login as su works.

You can easily remove the packages once the gems are build. But you may keep them for future use, for instance, during updating those gems.

1 Like

Such issues are common in coding and computing languages. To solve this, you will be required to download or install the ruby-dev package on Ubuntu or the ruby-devel package.