20

I am trying to install cocoapods to my MacBook and after I ran this code into the terminal gem install cocoapods I get the following error:

****** ~ % 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.6.0/gems/ffi-1.12.2/ext/ffi_c
/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 ./siteconf20200413-663-1dklrnl.rb extconf.rb
mkmf.rb can't find header files for ruby at /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/include/ruby.h

You might have to install separate package for the ruby development
environment, ruby-dev or ruby-devel for example.

extconf failed, exit code 1

Gem files will remain installed in /Library/Ruby/Gems/2.6.0/gems/ffi-1.12.2 for inspection.
Results logged to /Library/Ruby/Gems/2.6.0/extensions/universal-darwin-19/2.6.0/ffi-1.12.2/gem_make.out

2 Answers 2

36

Looks like you don't have installed Ruby development headers.

You can fix this by installing Xcode command-line tools by executing these two commands:

xcode-select --install
sudo xcodebuild -license

Changes will apply after the computer restart.

6
  • 2
    command lines was already installed for my case. 'sudo xcodebuild -license' and agreeing licence did the trick for me. I could be able to install cocoapods after that. Commented Apr 23, 2020 at 20:17
  • 15
    Also by Opening Xcode preferences > Locations > selecting Command Line Tools to be my Xcode worked for me.
    – EnasAZ
    Commented May 26, 2020 at 4:25
  • @EnasAZ Thank you. This worked for me. I had 10.1 selected and needed to update to 11.5 Commented Jul 21, 2020 at 4:27
  • Just bought an M1. Tried to install cocoapods. It fails. Google. Land here: github.com/CocoaPods/CocoaPods/issues/9907. I'm concerned. Something doesn't feel right. Keep googling. Find your answer. Makes most sense. Try it. BAM - cocoapods installs... thanks!
    – Kilmazing
    Commented Feb 19, 2021 at 1:13
  • This worked for me. I didn't have to restart computer. Commented Jun 18, 2022 at 2:37
13

Goto Xcode preferences then click on Locations -> Command Line Tools -> Click on the drop down and check if any of it is available. If yes then select and set it. Then try to install cocoa pods it works as expected.

If no option is available in the drop down for Command Line Tools then use following commnands

xcode-select --install
sudo xcodebuild -license
1
  • 2
    This should be the accepted answer, I think. Commented Sep 12, 2021 at 23:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.