30
votes

Am trying to reinstall cocoapods in my MacBook air after changing my SSD, now am getting this bellow error.

sudo gem install cocoapods

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 ./siteconf20200308-27204-6l0a5q.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

8

8 Answers

60
votes

Open Terminal

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

Reopen Terminal

rvm install ruby-2.6

rvm use ruby-2.6.3

rvm --default use 2.6.3

From MahmoudKhaled's comment on link

12
votes

For me it worked by installing a previous version of cocoapods

sudo gem install cocoapods -v 1.8.4

Hope it helps

8
votes

This error can be fixed by updating ruby to it's latest version version 2.3.0 is having that issue.

You can update the ruby version to latest one by following below steps.

  1. Check the version of Ruby installed on your Mac

Open terminal and type:

ruby -v

  1. Install the Ruby Version Manager rvm

In terminal,

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

Once this command has finished running you may need to restart your terminal for rvm to be recognised.

  1. Install the latest version of Ruby

    rvm install ruby-[version]

In my case this was

rvm install ruby-2.7.1

This took a while to run as it had to install a lot of dependencies and asked for my permission a couple of times.

  1. Set the latest version of Ruby as the one you want to use

You should now be running the latest version of Ruby. You can check as before with the ruby -v command as in step 1. If you’re find that you’re not, you can set this manually. In terminal type:

rvm use ruby-2.7.1

If you want to set this latest version of Ruby as the default version, in terminal type:

rvm --default use 2.7.1

After that done you can get your below command working for upgrading cocoapods

sudo gem install cocoapods
6
votes

Probably you have not selected the Command Line Tool in Xcode > Preference > Location after an update.

The sudo gem install cocoapods command works after the tool is selected in Xcode.

2
votes

Open terminal

xcode-select --install

Reopen Terminal

sudo gem install cocoapods

That's it!

1
votes

Error: gem native extension error while installing cocoapods

Answer: Follow below 3 Steps issue will be fixed.

Step 1: Open XCode go to below path

XCode > Preferences > Locations > Command Line Tools (select-Xcode)

Step 2: Open Terminal- Paste the below Command

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

Reopen Terminal -Paste the below Commands

Note: It will take 3-5 minutes

rvm install ruby-2.6

rvm use ruby-2.6.3

rvm --default use 2.6.3

Step3:

Open Terminal- Type below Command

sudo gem install cocoapods

Now gem native extension error while installing cocoapods will not come

Issue resolved.

0
votes

I had the same error, I was unable to upgrade cocopods and the problem was that homebrew was failing to update. I noticed that when trying to install a new ruby version with nvm, it was failing because it was trying to run homebrew update. So it seems nvm and homebrew are connected

I followed the instructions here: https://github.com/Homebrew/brew/issues/9420

basically brew update (was failing)

git -C /usr/local/Homebrew/Library/Taps/homebrew/homebrew-core fetch --unshallow

git -C /usr/local/Homebrew/Library/Taps/homebrew/homebrew-cask fetch --unshallow

brew update (successful)

brew install cocoapods

It didn't solve the error, but upgraded cocoapods in another way.

0
votes

enter image description here

I used all the codes before and showed up there, when I tried to run flutter doctor for the millesimal time...

CocoaPods 1.8.4 out of date (1.10.0 is recommended)

I just changed to: sudo gem install cocoapods -v 1.10.0

and apparently installed the cocoapods.