1

I have no experience with Ruby. When I try to do gem install nokogiri on MacOS I am getting.

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

    current directory: /Library/Ruby/Gems/2.3.0/gems/nokogiri-1.10.5/ext/nokogiri
/System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/bin/ruby -I /Library/Ruby/Site/2.3.0 -r ./siteconf20191105-81089-x3wjwy.rb extconf.rb
mkmf.rb can't find header files for ruby at /System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/lib/ruby/include/ruby.h

extconf failed, exit code 1

Gem files will remain installed in /Library/Ruby/Gems/2.3.0/gems/nokogiri-1.10.5 for inspection.
Results logged to /Library/Ruby/Gems/2.3.0/extensions/universal-darwin-18/2.3.0/nokogiri-1.10.5/gem_make.out
Shota
  • 6,910
  • 9
  • 37
  • 67
  • Have you tried the solutions detailed in this stack overflow question? https://stackoverflow.com/questions/33996523/error-installing-nokogiri-failed-to-build-gem-native-extension-libiconv-is-mi – Dennis Nov 05 '19 at 09:38
  • Yes, tried all of them. – Shota Nov 05 '19 at 10:47
  • What does the /Library/Ruby/Gems/2.3.0/extensions/universal-darwin-18/2.3.0/nokogiri-1.10.5/gem_make.out file say ? – Dennis Nov 05 '19 at 15:06
  • @Dennis it says: `current directory: /Library/Ruby/Gems/2.3.0/gems/nokogiri-1.10.5/ext/nokogiri /System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/bin/ruby -I /Library/Ruby/Site/2.3.0 -r ./siteconf20191105-81359-gkmop8.rb extconf.rb mkmf.rb can't find header files for ruby at /System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/lib/ruby/include/ruby.h extconf failed, exit code 1` – Shota Nov 05 '19 at 15:12
  • Try the commands in my answer. If it still fails you may want to go the `rbenv` route. – Dennis Nov 05 '19 at 20:08

2 Answers2

0

Did you try?

gem update --system
xcode-select --install
Ryan Wildry
  • 5,612
  • 1
  • 15
  • 35
Horacio
  • 2,865
  • 1
  • 14
  • 24
0

The following should fix your issue:

sudo rm -rf /Library/Developer/CommandLineTools
xcode-select --install
sudo xcodebuild -license accept
open /Library/Developer/CommandLineTools/Packages/macOS_SDK_headers_for_macOS_10.14.pkg
Dennis
  • 779
  • 4
  • 14