170
votes

I am trying to install cocoapods to my MacBook Pro running with OSX 10.9.1 (new Mavericks) and after type gem install cocoapods I get the following error:

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

        "/usr/local/rvm/rubies/ruby-1.9.3-p194/bin/ruby" -rubygems /usr/local/rvm/gems/ruby-1.9.3-p194/gems/rake-10.1.1/bin/rake RUBYARCHDIR=/Users/rangreenberg/gems/gems/xcodeproj-0.14.1/ext RUBYLIBDIR=/Users/rangreenberg/gems/gems/xcodeproj-0.14.1/ext
/usr/local/rvm/rubies/ruby-1.9.3-p194/bin/ruby extconf.rb
checking for -std=c99 option to compiler... *** extconf.rb failed ***
Could not create Makefile due to some reason, probably lack of
necessary libraries and/or headers.  Check the mkmf.log file for more
details.  You may need configuration options.

Provided configuration options:
    --with-opt-dir
    --with-opt-include
    --without-opt-include=${opt-dir}/include
    --with-opt-lib
    --without-opt-lib=${opt-dir}/lib
    --with-make-prog
    --without-make-prog
    --srcdir=.
    --curdir
    --ruby=/usr/local/rvm/rubies/ruby-1.9.3-p194/bin/ruby
/usr/local/rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/mkmf.rb:381:in `try_do': The compiler failed to generate an executable file. (RuntimeError)
You have to install development tools first.
    from /usr/local/rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/mkmf.rb:491:in `block in try_compile'
    from /usr/local/rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/mkmf.rb:443:in `with_werror'
    from /usr/local/rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/mkmf.rb:491:in `try_compile'
    from extconf.rb:24:in `block in <main>'
    from /usr/local/rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/mkmf.rb:790:in `block in checking_for'
    from /usr/local/rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/mkmf.rb:284:in `block (2 levels) in postpone'
    from /usr/local/rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/mkmf.rb:254:in `open'
    from /usr/local/rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/mkmf.rb:284:in `block in postpone'
    from /usr/local/rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/mkmf.rb:254:in `open'
    from /usr/local/rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/mkmf.rb:280:in `postpone'
    from /usr/local/rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/mkmf.rb:789:in `checking_for'
    from extconf.rb:23:in `<main>'
rake aborted!
Command failed with status (1): [/usr/local/rvm/rubies/ruby-1.9.3-p194/bin/...]

Tasks: TOP => default => ext
(See full trace by running task with --trace)


Gem files will remain installed in /Users/rangreenberg/gems/gems/xcodeproj-0.14.1 for inspection.
Results logged to /Users/rangreenberg/gems/gems/xcodeproj-0.14.1/ext/xcodeproj/gem_make.out
30

30 Answers

269
votes

Run following command

 brew cleanup -d -v 

Then run below command

brew install cocoapods 

Note: If you see failed to link then run brew link cocoapods

This is how it get solved for me

For someone who is having m1 chip system they need to run this via Rosetta

select Terminal and press cmd(⌘)+I and check the "Open using Rosetta" option. ( For m1 chip based mac )

90
votes

First, check the version of Ruby you are using.

$ruby -v
ruby 2.7.1p83 (2020-03-31 revision a0c7c23c9c) [x86_64-darwin18]
$ which ruby
usr/bin/ruby

Now use Homebrew to install the latest Ruby.

$ brew install ruby
==> ruby
By default, binaries installed by gem will be placed into:
/usr/local/lib/ruby/gems/2.7.0/bin

You may want to add this to your PATH.

ruby is keg-only, which means it was not symlinked into /usr/local,
because macOS already provides this software and installing another version in
parallel can cause all kinds of trouble.

If you need to have ruby first in your PATH run:

$ echo 'export PATH="/usr/local/opt/ruby/bin:$PATH"' >> /Users/xxx/.bash_profile

For compilers to find ruby you may need to set:

$ export LDFLAGS="-L/usr/local/opt/ruby/lib"
$ export CPPFLAGS="-I/usr/local/opt/ruby/include"

Follow the instructions to set PATH. Now you will go to see the installed Ruby. Make sure to replace the 'xxx' with your username.

$ echo 'export PATH="/usr/local/opt/ruby/bin:$PATH"' >> /Users/xxx/.bash_profile
$ echo 'export LDFLAGS="-L/usr/local/opt/ruby/lib"' >> ~/.bash_profile
$ echo 'export CPPFLAGS="-I/usr/local/opt/ruby/include"' >> ~/.bash_profile

$ source ~/.bash_profile

Finally, Make sure your PATH is in place.

$ ruby -v
ruby 2.7.1p83 (2020-03-31 revision a0c7c23c9c) [x86_64-darwin18]
$ which ruby
/usr/local/opt/ruby/bin/ruby

You're good to go! Make sure you install by specifying the save destination as follows.

$ sudo gem install -n /usr/local/bin cocoapods
69
votes

You need to install Xcode's developer tools. The easiest way to do this is through terminal (this question)

xcode-select --install
19
votes

if you're also seeing error: active developer path .. does not exist you may also have to do this

$ sudo xcode-select --reset
12
votes
brew reinstall ruby

Add the below to your path

export PATH="/usr/local/opt/ruby/bin:$PATH"

If needed add these flags.

export LDFLAGS="-L/usr/local/opt/ruby/lib"
export CPPFLAGS="-I/usr/local/opt/ruby/include"
12
votes

If none of above works then follow these steps

  1. sudo xcode-select --switch /Library/Developer/CommandLineTools
  2. sudo gem install cocoapods

If you get error like this '

ERROR:  While executing gem ... (Gem::FilePermissionError)
    You don't have write permissions for the /usr/bin directory

.'

then go to step 3

  1. $ sudo gem install -n /usr/local/bin cocoapods
9
votes

I fixed the problem by using ruby 2.0 (which is the preferred way on mavericks) or greater. In case you are using rvm just change to the correct ruby with:

rvm use ruby-2.0

After that gem install cocoapods worked correctly. To be more specific, I was using:

OSX 10.9.2
ruby-2.0.0-p353
cocoapods-0.32.1
9
votes

Update your gem tool first. This might take a while

sudo gem update --system

Use this instead

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

Latest CocoaPods 1.10.0 won't work.

you can verify the version with

pod --version
6
votes

First as wrote "Kevin" try to run in terminal:

xcode-select --install

If it doesn't help you download tools manually from apple developer site:

It helped me.

4
votes

Sometimes the issue is that your xcode tools version is too low. Try running these commands if you already haven't

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

4
votes

This command saved my day

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

To be confirmed check the pod version

pod --version

3
votes

First install Homebrew if you don't have it: https://brew.sh/index_pt-br

/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)"

Second, install ruby if you don't have it: https://www.ruby-lang.org/pt/documentation/installation/

brew install ruby

You can also follow these steps: https://gist.github.com/monicao/d372716cdfbb7e9cf692

Then, close your terminal and reopen it again.

Always use sudo to install cocoapods:

sudo gem install cocoapods
3
votes

I also had the same problem. This is probably happening because your computer has older version of ruby. So you need to first update your ruby. Mine worked for ruby 2.6.3 version

You need to first open terminal and put this code

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

Then put this command

rvm install ruby-2.6.3

This would install the ruby for you if it hasn' t been installed.After this just update the ruby to the new version

rvm use ruby-2.6.3

After this just make ruby 2.6.3 your default

rvm --default use 2.6.3

This would possibly fix your issue. You can now put the command

sudo gem install cocoapods

And the command

pod setup
2
votes

I fix the problem by follow step:

1:rvm install 2.0.0

2:rvm list * ruby-1.9.3-p545 [ x86_64 ] => ruby-2.0.0-p451 [ x86_64 ]

3:rvm 2.0.0 —default

4:pod update

2
votes

Alright,

I had the same issue. Tried to install pods to my project but never worked out. I updated Xcode, Updated Command Line tools, reinstalled cocoapods... almost everything.

Sitting on my ass , writing pod in terminal showed up a screen listing available commands.

I read all of them and noticed the command

pod setup

which does

+ setup               Setup the CocoaPods environment

After this line of code, my problem was fixed.

I hope my solution help other people in trouble like me.

2
votes

My way to solved:

First of all, i have new mac os 10.15.7 and Xcode

None of previous solutions worked for me too

I note that pods install in Library 2.6.0 and decided that it needs to be updated:

step 1

\curl -sSL https://get.rvm.io | bash -s stable --ruby

Ok!

Then i checked version: 2.6.0 - Why? In last string after install ruby, i noticed:

  • To start using RVM you need to run source /Users/abazhanov/.rvm/scripts/rvm in all your open shell windows, in rare cases you need to reopen all shell windows.

ok, let's do it:

step 2

source /Users/abazhanov/.rvm/scripts/rvm

Then i checked version: 2.7.0 - its ok!

step 3

sudo gem install cocoapods 

As a result: 34 gems installed

I understand that the new version of Pods simply did not install on the old version of Ruby

2
votes

Open Terminal

xcode-select --install
sudo xcodebuild -license accept
curl -L https://get.rvm.io | bash -s stable

Close and Reopen Terminal

rvm install ruby-2.6

sudo gem install cocoapods
pod install 

After completing right click on project top-left on android studio then click on Flutter -> Open IOS Module in Xcode

1
votes

I was having the same exact problem, although I had the latest version of the xcode command-line tools.

If you have homebrew installed, do brew install apple-gcc42. This immediately solved it for me.

1
votes

I was getting this error and had to completely reinstall cocoapods to fix it. Finally worked. Maybe this solution suits for anyone else.

sudo rm -rf home_folder/.cocoapods/

After that, did again

pod setup

and installed my libraries from zero, and everything worked.

Hope it helps!

1
votes

I got same problem and I just fixed with change my /usr/local/include folder to /usr/local/include_old

1
votes

I was facing quite a similar error, and it was my first time installing CocoaPods on macOS Catalina. Finally managed by installing Xcode Commandline Tools. Type in the following command into your Terminal. (As of this day, this file is around 248.3mb)

xcode-select --install

A dialog should appear asking you to approve the download and installation. It might take a while to download depending on your internet speed. Once the installation is successful. Attempt to install CocoaPods once more with the following command in Terminal.

sudo gem install cocoapods

Once complete use the following command to confirm if installation was successful

pod setup --verbose
1
votes

Worked for me in 2020 (Mac OS Catalina)

xcode-select --install

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

After trying various things Tosin Sotannde's method work for me first run this

sudo gem update --system

then

sudo gem install -n /usr/local/bin cocoapods -v 1.8.4
0
votes

I had multiple environments in my configuration, which was causing problems as rvm was interfering with the installation. Once ruby 2.x was detected the install went fine.

For my environment I did the following: 1. xcode-select --install 2. rvm implode (Note - too drastic - you may not need to do this, I didn't have any use for the older ruby installations, I removed them via rvm uninstall one-by-one and then used rvm implode 3. gem install cocoapods

This time the last command worked without any issues.

0
votes

You must use the command in Terminal for installing Command Line Tools:

xcode-select --install

If you receive the message as a result of "Can't install the software because it is not currently available from the Software Update server.", You must download manually Command Line Tools from Apple site.

0
votes

The same initial issue occurred when attempting to setup GoogleMaps in a Flutter app after running pod install on the iOS directory.

Running pod install the following error appeared:

zsh: /usr/local/bin/pod: bad interpreter: /System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/bin/ruby: no such file or directory

Next, after running sudo gem install cocoapods that resulted in another error similar to that shown at ERROR: Error installing cocoapods: ERROR: Failed to build gem native extension.

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

kevin recommends installing Xcode Developer Tools running:

xcode-select --install

and while highlighting the need to install the tools, the system again produced the same error as before when running the pod install command.

Refresing the tools by removing and reinstalling them became the next target. The tools are removed with the following command:

rm -rf /Library/Developer/CommandLineTools

And again installing the xcode developer tools using:

xcode-select --install

Then, sudo gem install cocoapods and pod install ran successfully.

0
votes

None of previous solutions worked for me...

My situation is a fresh clean install of macOS Catalina + XCODE;

It happen that I had to first run Xcode before install cocoa pods (in first run, Xcode setups machine with tools);

After that, cocoa pods worked fine.

0
votes

i had this issue when i tryed to install cocoapods by running the command "sudo gem install cocoapods", but i was able to install it with no problems using brew

0
votes

This should unshallow both the cask and the core repo.

brew tap homebrew/cask

followed by...

brew tap homebrew/core
0
votes

I have same issue, cocoapods was not installing and waste 3 to 4 hours to get solve this error and finally I got the solution,

step1: open the terminal and run "brew reinstall ruby" and terminal will guide you how to export the path step2: and then run "sudo gem install cocoapods"