Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Fix Apple’s broken 10.9.0-10.9.2 default Ruby gems installation.

On Mac OS X 10.9.0 through 10.9.2, Apple shipped a Ruby and RubyGems installation that was missing specifications for the libraries that are included with Ruby by default, which leads to the user having to install a gem like the JSON gem even though the user already has that library installed.

(This is even more problematic if you want users to be able to install gems without having to have a properly configured compiler toolchain. I.e. where you do not want users to have to install gems with C extensions, such as the JSON gem.)

This was fixed starting from Mac OS X 10.9.3.

What it should look like

The following libraries are installed by default and should have their specifications installed:

$ ls -l /Library/Ruby/Gems/2.0.0/specifications/default
-rw-r--r--  1 eloy  staff   766 Oct 28 13:26 bigdecimal-1.2.0.gemspec
-rw-r--r--  1 eloy  staff   601 Oct 28 13:26 io-console-0.4.2.gemspec
-rw-r--r--  1 eloy  staff   537 Oct 28 13:26 json-1.7.7.gemspec
-rw-r--r--  1 eloy  staff   341 Oct 28 13:26 minitest-4.3.2.gemspec
-rw-r--r--  1 eloy  staff  4836 Oct 28 13:26 psych-2.0.0.gemspec
-rw-r--r--  1 eloy  staff  1481 Oct 28 13:26 rake-0.9.6.gemspec
-rw-r--r--  1 eloy  staff  2758 Oct 28 13:26 rdoc-4.0.0.gemspec
-rw-r--r--  1 eloy  staff   762 Oct 28 13:26 test-unit-2.0.0.0.gemspec

The fix

To fix, for instance, the JSON gem, perform the following steps:

$ sudo mkdir /Library/Ruby/Gems/2.0.0/specifications/default
$ sudo curl -o /Library/Ruby/Gems/2.0.0/specifications/default/json-1.7.7.gemspec \
               https://raw.githubusercontent.com/flori/json/v1.7.7/json.gemspec

After which you should have the following:

$ ls -l /Library/Ruby/Gems/2.0.0/specifications/default
-rw-r--r--  1 root  wheel  4842 Nov  3 13:32 json-1.7.7.gemspec
@OudomPhun
Copy link

OudomPhun commented May 25, 2017

why when i try to do that - show that -bash: -rw-r--r--: command not found. Help please

@fyonacya
Copy link

fyonacya commented Apr 16, 2020

Thank you

@dadrew
Copy link

dadrew commented Dec 23, 2020

To see why this extension failed to compile, please check the mkmf.log which can be found here:

/Library/Ruby/Gems/2.6.0/extensions/universal-darwin-19/2.6.0/ffi-1.14.2/mkmf.log

extconf failed, exit code 1
how do you fix this?

@tehilaR2
Copy link

tehilaR2 commented Feb 17, 2021

run sudo curl -o /Library/Ruby/Gems/2.6.0/specifications/default/json-1.7.7.gemspec https://raw.githubusercontent.com/flori/json/v1.7.7/json.gemspec

@golgo013
Copy link

golgo013 commented Mar 4, 2021

tried your code and
curl: no URL specified!
curl: try 'curl --help' or 'curl --manual' for more information

also in mkmf.log I see below error message. would be good if anyone can guide how to correct it

package configuration for libffi is not found
"xcrun clang -o conftest -I/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX11.1.sdk/System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/include/ruby-2.6.0/universal-darwin19 -I/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX11.1.sdk/System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/include/ruby-2.6.0/ruby/backward -I/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX11.1.sdk/System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/include/ruby-2.6.0 -I. -D_XOPEN_SOURCE -D_DARWIN_C_SOURCE -D_DARWIN_UNLIMITED_SELECT -D_REENTRANT -g -Os -pipe -DHAVE_GCC_ATOMIC_BUILTINS conftest.c -L. -L/System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib -L. -L/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.15.Internal.sdk/usr/local/lib -arch x86_64 -lruby.2.6 "
In file included from conftest.c:1:
In file included from /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX11.1.sdk/System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/include/ruby-2.6.0/ruby.h:33:
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX11.1.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.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX11.1.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/MacOSX10.15.sdk/System/Library/Frameworks')
1 error generated.
checked program was:
/* begin */
1: #include "ruby.h"
2:
3: int main(int argc, char *argv)
4: {
5: return 0;
6: }
/
end */

@ahmadsb
Copy link

ahmadsb commented Mar 15, 2021

  1. Goto " /Library/Ruby/" and delete gem folder and then
  2. [gem install cocoapods] or [sudo gem install cocoapods]
  3. run app it's work fine

@golgo013
Copy link

golgo013 commented Mar 15, 2021

  1. Goto " /Library/Ruby/" and delete gem folder and then
  2. [gem install cocoapods] or [sudo gem install cocoapods]
  3. run app it's work fine

Tried and still says gem file permission error

@dadrew
Copy link

dadrew commented Mar 15, 2021

@mikecasey93
Copy link

mikecasey93 commented Mar 19, 2021

When I try to install i get this can you help please
/System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/rubygems/stub_specification.rb:116:in `readline': Is a directory @ io_fillbuf - fd:9 /Library/Ruby/Gems/2.6.0/specifications/default/json-1.7.7.gemspec (Errno::EISDIR)

@dadrew
Copy link

dadrew commented Mar 19, 2021

@timshe
Copy link

timshe commented Apr 5, 2021

I am having similar error installing cocoapods on MacOS 10.15.7 (Catalina) pls help...

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

current directory: /Library/Ruby/Gems/2.6.0/gems/json-2.5.1/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 ./siteconf20210405-3282-1t61n8s.rb extconf.rb
creating Makefile

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

current directory: /Library/Ruby/Gems/2.6.0/gems/json-2.5.1/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.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX11.1.sdk/System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/include/ruby-2.6.0/ruby.h:33:
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX11.1.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.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX11.1.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.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

@mdrijwan
Copy link

mdrijwan commented Jun 23, 2021

same here. facing the following error.

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

    current directory: /Library/Ruby/Gems/2.6.0/gems/json-2.5.1/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 ./siteconf20210624-83152-1eugefu.rb extconf.rb
creating Makefile

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

current directory: /Library/Ruby/Gems/2.6.0/gems/json-2.5.1/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/MacOSX12.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/MacOSX12.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/MacOSX12.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.5.1 for inspection.
Results logged to /Library/Ruby/Gems/2.6.0/extensions/universal-darwin-20/2.6.0/json-2.5.1/gem_make.out

any fix?

@ZhongHao-FS
Copy link

ZhongHao-FS commented Sep 7, 2021

I have noticed that all you guys are having these problems since 2020 while the original solution was set for 2015 versions, and that does not work anymore. Fortunately, I have found a solution that solves the new problem, here is the link: https://www.bswen.com/2020/10/others-how-to-resolve-mac-install-cocoapods-error.html
It worked perfectly for Firebase installation on my XCode project. Let us know if you find this working or not!

@Ahmed-Mujahid
Copy link

Ahmed-Mujahid commented Sep 10, 2021

I have noticed that all you guys are having these problems since 2020 while the original solution was set for 2015 versions, and that does not work anymore. Fortunately, I have found a solution that solves the new problem, here is the link: https://www.bswen.com/2020/10/others-how-to-resolve-mac-install-cocoapods-error.html
It worked perfectly for Firebase installation on my XCode project. Let us know if you find this working or not!

having same issue after using this solution. Although after using this command
$ ls -l /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.15.sdk/System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/include/ruby-2.6.0

i had this output
total 8
drwxr-xr-x 23 root wheel 736 Oct 8 2020 ruby
-rw-r--r-- 1 root wheel 868 Jun 6 2020 ruby.h
drwxr-xr-x 4 root wheel 128 Aug 10 2020 universal-darwin19

i still followed the step and its giving me the same error

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment