16

sudo gem install cocoapods throws mkmf.rb can't find header files for ruby.

The full output:

Last login: Sat Mar 21 19:00:12 on ttys000
praneeths-MacBook-Air:~ praneeth$ sudo gem install cocoapods
Password:
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.3.0/gems/ffi-1.12.2/ext/ffi_c
/System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/bin/ruby -r ./siteconf20200321-2325-4gn5jh.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/ffi-1.12.2 for inspection.
Results logged to /Library/Ruby/Gems/2.3.0/extensions/universal-darwin-18/2.3.0/ffi-1.12.2/gem_make.out
im-a-teapot
  • 398
  • 4
  • 12

1 Answers1

22

This also happened to me and it is because you have to update your ruby version. Someone already posted an issue on cocoapods github repository. That issue pointed me to this stackoverflow answer and this is the solution copy-pasted from that answer:

Open Terminal

curl -L https://get.rvm.io | bash -s stable

Close and Reopen Terminal

rvm install ruby-2.6

rvm use ruby-2.6.5

rvm --default use 2.6.5

From MahmoudKhaled's comment on link

Screenshot

Jayprakash Dubey
  • 35,723
  • 18
  • 170
  • 177
im-a-teapot
  • 398
  • 4
  • 12
  • 2
    This should be accepted as answer. I spent more than four hours and tried all answers mentioned on stackoverflow but none worked until stumbled upon this answer. – Jayprakash Dubey May 17 '20 at 16:49
  • Thanks, this is essentially the right answer. In my particular case, afterwards I also had to `sudo rm -rf /Library/Ruby/Gems/2.3.0` to delete the old Cocoapods then `sudo gem install cocoapods` to reinstall. And `rvm` didn't work until I deleted MacPorts and reinstalled it. Wish macOS had a proper package manager. – sudo Dec 21 '20 at 22:55
  • Love you man, you saved me! Trying to serve a jekyll to github pages and all the ruby versions were crashing but 2.6 jaja – M. Mariscal Jan 24 '21 at 18:25