環境

# uname -a
Linux ip-10-122-6-110 3.2.30-49.59.amzn1.x86_64 #1 SMP Wed Oct 3 19:54:33 UTC 2012 x86_64 x86_64 x86_64 GNU/Linux
# ruby -v
ruby 1.8.7 (2012-10-12 patchlevel 371) [x86_64-linux]
# gem -v
1.8.11

現象

# gem install json

Gem::Installer::ExtensionBuildError: ERROR: Failed to build gem native extension. 

        /usr/bin/ruby extconf.rb
mkmf.rb can't find header files for ruby at /usr/lib/ruby/ruby.h

Gem files will remain installed in /home/redmine/.bundler/tmp/5531/gems/json-1.7.7 for inspection.
Results logged to /home/redmine/.bundler/tmp/5531/gems/json-1.7.7/ext/json/ext/generator/gem_make.out
An error occurred while installing json (1.7.7), and Bundler cannot continue.
Make sure that `gem install json -v '1.7.7'` succeeds before bundling.

解決方法

ruby-develが必要。さらに、gcc、makeなどの開発環境も必要なので、yum でインストールする。

yum install ruby-devel gcc make

facebook slideshare rubygems github qiita