When I try sudo gem install json I get the following error

48,265

Solution 1

With Mavericks, you can solve this problem by installing the Xcode Command Line Tools from the command line like this:

xcode-select --install

Update: Don't forget to accept the license agreement after you install or update:

sudo xcodebuild -license

Solution 2

If you have this problem:

ERROR:  Error installing json:
ERROR: Failed to build gem native extension.

and you are using a Mac with OS X (tested with 10.8.1 Mountain Lion), you need to download Xcode from the Mac App Store (or from developer.apple.com if you have a dev account - it's free BTW and you can download a DMG installer)

The latest Xcode versions (I'm using Xcode 4.4.1) does NOT include command line tools. Now you need to install this additional package inside Xcode. Once done, your problem is fixed.

To do that, open Xcode, go to Preferences > Downloads > Components. Install "Command Line Tools". You're done. Now you can install the json Ruby gem.

enter image description here

Solution 3

You are missing the ruby development headers. To install these on an OS like ubuntu you should use:

aptitude install ruby1.8-dev

Solution 4

Installing Xcode command line tools... should fix this issue.

Solution 5

A simple google search reveals this:

If you get the can't find header files for ruby error message when trying to build an extension or a gem, it means that Ruby cannot locate its header files.

Header files are not delivered by default with Mac OS X, you need to install the Xcode Tools package after the installation. You can find it in the Optional Installs / Xcode Tools directory on the Leopard DVD.

Share:
48,265
Admin
Author by

Admin

Updated on March 22, 2020

Comments

  • Admin
    Admin about 4 years

    I need to install the JSON gem to start my app but I get the error below whenever I try to install the json gem. Can anyone help me out. I'm using rails 2.2.2 and gems 1.3.1.

    Arions-macbook-pro:.ssh arion$ sudo gem install json
    Password:
    Sorry, try again.
    Password:
    Building native extensions.  This could take a while...
    ERROR:  Error installing json:
        ERROR: Failed to build gem native extension.
    
    /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/bin/ruby extconf.rb install json
    can't find header files for ruby.
    
    
    Gem files will remain installed in /Library/Ruby/Gems/1.8/gems/json-1.1.4 for inspection.
    Results logged to /Library/Ruby/Gems/1.8/gems/json-1.1.4/ext/json/ext/parser/gem_make.out