skip to Main Content

I’m not able to install json gem on my M1 MacBook. This is the command I’m running.

sudo gem install json -v '2.6.2'

This is the error I’m getting. I’m guessing it because it’s picking up Xcode 14.1 Beta 3, but I’m not sure how to have it use a different version of Xcode or if that’s the problem.

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

    current directory: /Library/Ruby/Gems/2.6.0/gems/json-2.6.2/ext/json/ext/generator
/System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/bin/ruby -I /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0 -r ./siteconf20221018-37799-1wcwkww.rb extconf.rb
creating Makefile

current directory: /Library/Ruby/Gems/2.6.0/gems/json-2.6.2/ext/json/ext/generator
make "DESTDIR=" clean

current directory: /Library/Ruby/Gems/2.6.0/gems/json-2.6.2/ext/json/ext/generator
make "DESTDIR="
compiling generator.c
In file included from generator.c:1:
In file included from ./../fbuffer/fbuffer.h:5:
In file included from /Applications/Xcode-beta.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX13.0.sdk/System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/include/ruby-2.6.0/ruby.h:33:
/Applications/Xcode-beta.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX13.0.sdk/System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/include/ruby-2.6.0/ruby/ruby.h:24:10: fatal error: 'ruby/config.h' file not found
#include "ruby/config.h"
         ^~~~~~~~~~~~~~~
/Applications/Xcode-beta.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX13.0.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 '/Applications/Xcode-beta.app/Contents/Developer/Platforms/MacOSX.platform/Developer/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 /Library/Ruby/Gems/2.6.0/gems/json-2.6.2 for inspection.
Results logged to /Library/Ruby/Gems/2.6.0/extensions/universal-darwin-21/2.6.0/json-2.6.2/gem_make.out

4

Answers


  1. This issue was already reported here, https://github.com/rubygems/bundler/issues/4462.
    Can you try bundle update && bundle install.
    bundle update will install all of your dependencies, but if you dont want to update all dependencies, try bundle update json only.

    Login or Signup to reply.
  2. The issue here is:

    1. Assuming you’re trying to install a modern 2.x version of JSON, this error is because it can’t see the ruby development tools.
    2. This is because MacOS doesn’t include ruby development tools for its base-level version of ruby. That version of ruby is used for some very core-level things on Mac and they lock it down pretty intensely.
    3. The solution is to use rbenv to install a new, user-controlled copy of ruby. This answer has a good step-by-step of how to do that, but the TLDR; is get brew, run brew install rbenv ruby-build, and then run rbenv install 2.6.10 && rbenv global 2.6.10 && rbenv rehash. Then restart your terminal.
    4. Now gem install commands should target the copy of ruby you just installed. (You can validate this by running ruby --version and making sure it lists the version you installed in step 3.) This should fix your issue installing json, whether via gem install or bundle install.
    Login or Signup to reply.
  3. resolved by CocoaPods/CocoaPods#10286
    curl -sSL https://get.rvm.io | bash -s stable
    close and reopen terminal
    rvm install ruby@latest
    rvm use ruby-3.0.0 –default

    Login or Signup to reply.
  4. These steps helped me https://github.com/facebook/react-native/issues/35836#issuecomment-1397633782

    Note for this post. Don’t use sudo to install any dependencies

    I unistalling all, literally… And install all again winthout
    sudo!!!!

    after 7 days… my problem was permissions because i installed some
    dependencies with sudo and any rubys versions and etc……

    delete all cache or folders, and start of zero inside of opt/homebrew
    erease all

    now go your folder now use cmd + shift + .

    your see hide folders delete all… caution this! delete only what you
    are sure are remnants of a bad installation of the environment

    try install all again winthout sudo

    homebrew watchman node (lts) Zulu11 (Java) cocoa pods gem

    Only in my .zshrc path envrioments Rbenv, homebrew gem (see docs)

    My OS

    macOS 13.1 Ventura Apple Silicon M2 Tools of Xode 14.x (lts)

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search