333

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
1
  • Try to switch ruby to homebrew version. brew install ruby brew link --overwrite ruby If you need to have ruby first in your PATH run: echo 'export PATH="/usr/local/opt/ruby/bin:$PATH"' >> ~/.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" For pkg-config to find ruby you may need to set: export PKG_CONFIG_PATH="/usr/local/opt/ruby/lib/pkgconfig" Commented Nov 9, 2021 at 12:26

40 Answers 40

628

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

If linking is getting failed then run

brew link --overwrite 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 )

Sign up to request clarification or add additional context in comments.

12 Comments

Yes. After an hour of trying to update things with rvm and gem, trying with brew worked like charm. Thanks!
After using 'brew link cocoapods' to fix link error, I occurred another error 'Could not symlink bin/pod'. I fix the symlink error by run 'brew link --overwrite cocoapods'.
if "brew link cocoapods" FAILED, use: brew link --overwrite cocoapods
I was getting an installation error while trying to install using gem (ruby), but with homebrew it's working fine.
Apparently cocopods has been removed from Homebrew. I ran the suggested command. The console returned this: ==> Searching for similarly named formulae... Error: No similarly named formulae found. Error: No available formula or cask with the name "cocopods". ==> Searching for a previously deleted formula (in the last month)... Error: No previously deleted formula found. ==> Searching taps on GitHub... Error: No formulae found in taps.
|
148

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

6 Comments

Worked for my MacOS Catalina 10.15.7. Thank you so much!
Worked for me also MacOs Big Sur 11.0.1. Thanks very much, bro you saved me. I have searched a lot for about 4 hours. You saved me Thanks agaian.
After spending almost 2 days to figure this out, finally this solution worked!
Something is wrong with my path on MacOS Catalina 10.15.7 I have check with below command which ruby /Users/ashish.chaudhary/.rvm/rubies/ruby-3.0.1/bin/ruby Still the issue is same for me. Issue could be the path of my ruby?
@Ashish yes it seems like. Try to uninstall ruby completely and re-install using brew.
|
74

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

xcode-select --install

11 Comments

When i type your suggestion i get 'Can't install the software because it is not currently available from the Software Update server.' :/
Try the other option from the developer website.
Already did, same problem, can't get the Command line tool, see this: discussions.apple.com/message/23822686#23822686
You can download the Command Line Tool manually from developer.apple.com/downloads/index.action
Can you tell us why is this needed? And how did you figure it out?
|
23

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

$ sudo xcode-select --reset

2 Comments

tried many things, set the xode command line tool manually, updated ruby, updated macOS but nothing worked. But this simple command fixed it. Thanks a lot.
I have tried 100 of other things but nothing worked but this worked perfectly fine.
22

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

Comments

19
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"

Comments

18

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

1 Comment

why latest version of cocoapods is not working any idea??
13

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

First install the Ruby Version Manager rvm:

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

Then use

source ~/.rvm/scripts/rvm 

Then install the latest version of ruby:

rvm install ruby-2.7.2

Then flow this (your Terminal) output Next step:

echo 'eval "$(/opt/homebrew/bin/brew shellenv)"' >> /Users/nec/.zprofile 

Then use

eval "$(/opt/homebrew/bin/brew shellenv)"

Finally try again to install the cocoapods:

sudo gem install cocoapods

3 Comments

I solved the problem using the above commands .
Can you clarify the /Users/nec/.zprofile directory? I'm assuming this is just whatever bash profile or whatever we use? I added the eval command to my .bashrc & .zprofile for good measure, but I'm not familiar with .zprofile, so not sure if it's necessary to have it in both?
.zprofile file path show your terminal output .
9

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

Comments

9

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

Comments

7

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

Comments

6

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.

Comments

5

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

Comments

5

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

Comments

4

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

Comments

4

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

Comments

3

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

Comments

3

If you installed it through Brew, you can solve it with a simple command.

brew update

brew upgrade

Comments

3

i had this issue when i tryed to install cocoapods by running

sudo gem install cocoapods

but i was able to install it with no problems using brew

4 Comments

Please share the code that you ran using brew. It will be helpful to show different solutions to the problem.
just run "brew install cocoapods". if you don't have brew installed on your machine you can see the installation guide on their website
This worked after having an error with 'sudo gem install cocoapods' As others have mentioned, use HomeBrew: brew install cocoapods A 2nd error: 'Could not symlink bin/xcodeproj' Do this: rm '/usr/local/bin/xcodeproj' -> yes at prompt. Then run: 'brew link --overwrite cocoapods' Run flutter doctor VSCode extension. You should see successful install.
That worked perfectly with no errors, thanks mate.
2

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

Comments

2

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.

Comments

2

I suppose you have run a gem update before installing the cocoapods gem, so all your gems should be updated.

That message is a new warning introduced with XCode 5.1, that now threats unknown parameters as errors. You didn't specify which version of cocoapods and XCode you are using, but my guess is that there is a mismatch between the two. Maybe Xcode is too old? You are installing a brand new cocoapods so at least that should be the latest available.

Instead of updating XCode, you could try disabling that warning and hope that the compilation completes successfully setting an environment variable just before installing cocoapods, with this:

ARCHFLAGS=-Wno-error=unused-command-line-argument-hard-error-in-future gem install cocoapods

Comments

2

try to install cocoapods using brew. i found it here Apple

Try

brew install cocoapods

it will get cocoapods installed without this error.

enter image description here

Comments

2

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.

Comments

1

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.

2 Comments

Error: No available formula for apple-gcc42
brew install homebrew/dupes/apple-gcc42
1

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

Comments

1

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

Comments

1

Worked for me in 2020 (Mac OS Catalina)

xcode-select --install

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

Comments

1

I follow this steps to install Cocoapods. May be it useful for you.

  1. Open Terminal
  2. gem install cocoapods
  3. pod setup

Comments

1

I faced same issue on macOS Catalina. Even though Installing with Homebrew worked, I was just curious why gem install cocoapods fails, even it is the preferred or mentioned method of installation in their official documentation.

I tried almost all solutions above and may be some other too, I found while googling the issue.

Finally today I deleted the Xcode 12.4, I have, and installed again, actually for some other reason. Just for curiosity, I tried gem install cocoapods again, and now it got worked, and installed cocoapods, the same way mentioned in the official documentation.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.