How do I fix the “ERROR: Failed to build gem native extension.” error when installing cocoapods?

Viewed 6269

I'm trying to install cocoapods on a brand new Mac OS X 11.1. I've run these commands:

sudo gem install cocoapods -n /usr/local/bin

However, when I run the last command, I get this error:

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

    current directory: /Library/Ruby/Gems/2.6.0/gems/ffi-1.14.2/ext/ffi_c
/System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/bin/ruby -I /Library/Ruby/Site/2.6.0 -r ./siteconf20201226-10485-158gl5m.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.14.2 for inspection.
Results logged to /Library/Ruby/Gems/2.6.0/extensions/universal-darwin-20/2.6.0/ffi-1.14.2/gem_make.out

How do I do that?

3 Answers
sudo gem update --system
xcode-select --install  
sudo gem install compass -n /usr/local/bin
sudo gem install cocoapods -n /usr/local/bin

it solved my problem

None of the solutions proposed here worked for me, my solution was to update ruby to this version:

rvm install ruby-2.6.3
rvm use ruby-2.6.3
rvm --default use 2.6.3

then run:

sudo gem install cocoapods

I have macOS catelina 10.15 and xcode 11.4 and following setups solved my issue.

  • Open Xcode
  • Click on the Xcode tab at top left corner
  • Open preferences >> Locations Tab
  • Select Command Line Tools

For some reason, there were no command line tools selected, so this caused issues for me. I downloaded a beta version of Xcode, and none were selected when I updated to the latest version.

Related