Unable to install cocoa pods
Asked Answered
N

4

26

I want to install cocoapods on MacOS to run the pod command. But on doing

sudo gem install cocoa-pods

I get the following:

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

    current directory: /usr/local/lib/ruby/gems/2.7.0/gems/ffi-1.13.1/ext/ffi_c
/usr/local/opt/ruby/bin/ruby -I /usr/local/Cellar/ruby/2.7.1_2/lib/ruby/2.7.0 -r ./siteconf20200702-22528-1o4wbn0.rb extconf.rb
checking for ffi.h... *** 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/Cellar/ruby/2.7.1_2/bin/$(RUBY_BASE_NAME)
    --with-ffi_c-dir
    --without-ffi_c-dir
    --with-ffi_c-include
    --without-ffi_c-include=${ffi_c-dir}/include
    --with-ffi_c-lib
    --without-ffi_c-lib=${ffi_c-dir}/lib
    --enable-system-libffi
    --disable-system-libffi
    --with-libffi-config
    --without-libffi-config
    --with-pkg-config
    --without-pkg-config
    --with-ffi-dir
    --without-ffi-dir
    --with-ffi-include
    --without-ffi-include=${ffi-dir}/include
    --with-ffi-lib
    --without-ffi-lib=${ffi-dir}/lib
/usr/local/Cellar/ruby/2.7.1_2/lib/ruby/2.7.0/mkmf.rb:471:in `try_do': The compiler failed to generate an executable file. (RuntimeError)
You have to install development tools first.
    from /usr/local/Cellar/ruby/2.7.1_2/lib/ruby/2.7.0/mkmf.rb:613:in `try_cpp'
    from /usr/local/Cellar/ruby/2.7.1_2/lib/ruby/2.7.0/mkmf.rb:1124:in `block in have_header'
    from /usr/local/Cellar/ruby/2.7.1_2/lib/ruby/2.7.0/mkmf.rb:971:in `block in checking_for'
    from /usr/local/Cellar/ruby/2.7.1_2/lib/ruby/2.7.0/mkmf.rb:361:in `block (2 levels) in postpone'
    from /usr/local/Cellar/ruby/2.7.1_2/lib/ruby/2.7.0/mkmf.rb:331:in `open'
    from /usr/local/Cellar/ruby/2.7.1_2/lib/ruby/2.7.0/mkmf.rb:361:in `block in postpone'
    from /usr/local/Cellar/ruby/2.7.1_2/lib/ruby/2.7.0/mkmf.rb:331:in `open'
    from /usr/local/Cellar/ruby/2.7.1_2/lib/ruby/2.7.0/mkmf.rb:357:in `postpone'
    from /usr/local/Cellar/ruby/2.7.1_2/lib/ruby/2.7.0/mkmf.rb:970:in `checking_for'
    from /usr/local/Cellar/ruby/2.7.1_2/lib/ruby/2.7.0/mkmf.rb:1123:in `have_header'
    from extconf.rb:10:in `system_libffi_usable?'
    from extconf.rb:42:in `<main>'

To see why this extension failed to compile, please check the mkmf.log which can be found here:

  /usr/local/lib/ruby/gems/2.7.0/extensions/x86_64-darwin-19/2.7.0/ffi-1.13.1/mkmf.log

extconf failed, exit code 1

Gem files will remain installed in /usr/local/lib/ruby/gems/2.7.0/gems/ffi-1.13.1 for inspection.
Results logged to /usr/local/lib/ruby/gems/2.7.0/extensions/x86_64-darwin-19/2.7.0/ffi-1.13.1/gem_make.out

The mkmf.log file is:

package configuration for libffi is not found
"clang -o conftest -I/usr/local/Cellar/ruby/2.7.1_2/include/ruby-2.7.0/x86_64-darwin19 -I/usr/local/Cellar/ruby/2.7.1_2/include/ruby-2.7.0/ruby/backward -I/usr/local/Cellar/ruby/2.7.1_2/include/ruby-2.7.0 -I.  -I/usr/local/opt/libyaml/include -I/usr/local/opt/[email protected]/include -I/usr/local/opt/readline/include -D_XOPEN_SOURCE -D_DARWIN_C_SOURCE -D_DARWIN_UNLIMITED_SELECT -D_REENTRANT   -O3 -ggdb3 -Wall -Wextra -Wdeprecated-declarations -Wdivision-by-zero -Wimplicit-function-declaration -Wimplicit-int -Wpointer-arith -Wshorten-64-to-32 -Wwrite-strings -Wmissing-noreturn -Wno-constant-logical-operand -Wno-long-long -Wno-missing-field-initializers -Wno-overlength-strings -Wno-parentheses-equality -Wno-self-assign -Wno-tautological-compare -Wno-unused-parameter -Wno-unused-value -Wunused-variable -Wextra-tokens  -fno-common -pipe conftest.c  -L. -L/usr/local/Cellar/ruby/2.7.1_2/lib -L/usr/local/opt/libyaml/lib -L/usr/local/opt/[email protected]/lib -L/usr/local/opt/readline/lib -L. -fstack-protector-strong -L/usr/local/lib -L/usr/local/opt/libyaml/lib -L/usr/local/opt/[email protected]/lib -L/usr/local/opt/readline/lib     -lruby.2.7   "
In file included from conftest.c:1:
In file included from /usr/local/Cellar/ruby/2.7.1_2/include/ruby-2.7.0/ruby.h:33:
In file included from /usr/local/Cellar/ruby/2.7.1_2/include/ruby-2.7.0/ruby/ruby.h:29:
/usr/local/Cellar/ruby/2.7.1_2/include/ruby-2.7.0/ruby/defines.h:126:10: fatal error: 'stdio.h' file not found
#include <stdio.h>
         ^~~~~~~~~
1 error generated.
checked program was:
/* begin */
1: #include "ruby.h"
2: 
3: int main(int argc, char **argv)
4: {
5:   return !!argv[argc];
6: }
/* end */


and running

brew install libffi

gives:

% brew install libffi
Warning: libffi 3.3 is already installed and up-to-date
To reinstall 3.3, run `brew reinstall libffi`

How to fix this?

And when I install cocoapods using brew, I get:

Warning: cocoapods 1.9.3 is already installed and up-to-date
To reinstall 1.9.3, run `brew reinstall cocoa-pods

Yet when I do:

pod --version

I get:

pod --version
/System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/universal-darwin19/rbconfig.rb:229: warning: Insecure world writable dir /Users/prikshetsharma/Library in PATH, mode 040777
Traceback (most recent call last):
    2: from /usr/local/bin/pod:23:in `<main>'
    1: from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/rubygems.rb:302:in `activate_bin_path'
/System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/rubygems.rb:283:in `find_spec_for_exe': can't find gem cocoapods (>= 0.a) with executable pod (Gem::GemNotFoundException)

When I run the pod command, it wants to find the gem, and not the pod installed using brew.

-- EDIT --

The brew config

HOMEBREW_VERSION: 2.4.3
ORIGIN: https://github.com/Homebrew/brew
HEAD: c69d97aaa5ba07e8c2af3708c8093ca0875cfb06
Last commit: 3 days ago
Core tap ORIGIN: https://github.com/Homebrew/homebrew-core
Core tap HEAD: 2820accc9a0486a8d5f0766bcf01fb560b9d3f9f
Core tap last commit: 14 hours ago
HOMEBREW_PREFIX: /usr/local
HOMEBREW_MAKE_JOBS: 16
CPU: 16-core 64-bit kabylake
Homebrew Ruby: 2.6.3 => /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/bin/ruby
Clang: 11.0 build 1103
Git: 2.24.3 => /Applications/Xcode.app/Contents/Developer/usr/bin/git
Curl: 7.64.1 => /usr/bin/curl
Java: 1.8.0_241
macOS: 10.15.5-x86_64
CLT: 11.5.0.0.1.1588476445
Xcode: 11.5

Noisemaker answered 2/7, 2020 at 15:52 Comment(1)
I have a similar problem! Could somebody check it out ? #72060664Monney
Q
80

I had a similar issue. I solved by installing the latest version of ruby (2.7.2).

First install the Ruby Version Manager rvm:

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

To skip having to closing and reopening the terminal, run

source ~/.rvm/scripts/rvm

Then install the latest version of ruby:

rvm install ruby-2.7.2

Finally try again to install the cocoapods:

sudo gem install cocoapods
Qualls answered 27/11, 2020 at 7:20 Comment(11)
rvm command not found :( what should I do?Disclose
find the solution, I have to close the terminal first, then execute rvm install ruby-2.7.2Disclose
I had to run this which I noticed in the terminal output: * To start using RVM you need to run source /Users/{username}/.rvm/scripts/rvmCrackle
export PATH="$PATH:$HOME/.rvm/bin"Airy
thanks a lot, worked for me on Catalina 10.15.7Rhoden
@sarah I had the same issue and ran source /Users/{My name}/.rvm/scripts/rvm before running rvm install ruby-2.7.2 and it worked. It said to do this in the output of the first command for me.Maighdiln
this works for me! also, am using brew and nothing went wrong using rvm. thank you.Staggers
That is the only answer that works for meApery
Thanks. This is the only thing that worked for me. I'm on Big Sur 11.6.2.Shiff
Worked for me on MacOS Monterey iMac late 2015Kareem
THANK YOU! This strategy resolved my issue! Much obliged!!!Adabelle
G
13

I think the most reliable solution is to use:

brew install cocoapods

Which should resolve missing / corrupted dependencies on its own.

PS: This obviously involves installing brew, but I am willing to bet you already have it in your system.

Gains answered 4/1, 2021 at 14:40 Comment(0)
C
5

Here is what I did on my Mojave machine:

  • brew reinstall cocoapods
  • brew link --overwrite cocoapods, override the default pod
$ brew reinstall cocoapods
==> Downloading https://homebrew.bintray.com/bottles/cocoapods-1.9.3.mojave.bottle.tar.gz
==> Downloading from https://akamai.bintray.com/07/074e5b53b7a054c132582183dcf47546ddd028a7beb9fcdc653fe4a43225bcf3?__gda__=exp=1593894546~hmac=8b
######################################################################## 100.0%
==> Reinstalling cocoapods
==> Pouring cocoapods-1.9.3.mojave.bottle.tar.gz
Error: The `brew link` step did not complete successfully
The formula built, but is not symlinked into /usr/local
Could not symlink bin/pod
Target /usr/local/bin/pod
already exists. You may want to remove it:
  rm '/usr/local/bin/pod'

To force the link and overwrite all conflicting files:
  brew link --overwrite cocoapods

To list all files that would be deleted:
  brew link --overwrite --dry-run cocoapods

Possible conflicting files are:
/usr/local/bin/pod
/usr/local/bin/xcodeproj
==> Summary
🍺  /usr/local/Cellar/cocoapods/1.9.3: 12,705 files, 28.0MB

$ brew link --overwrite cocoapods
Linking /usr/local/Cellar/cocoapods/1.9.3... 2 symlinks created

ls check the installation and version test

$ ls -al $(which pod)
lrwxr-xr-x  1 rchen  staff  33 Jul  4 16:17 /usr/local/bin/pod -> ../Cellar/cocoapods/1.9.3/bin/pod

$ pod --version
1.9.3

Let me know if it works, also attach your brew config if it is still an issue.

Chrysler answered 4/7, 2020 at 20:21 Comment(4)
Still getting the error. The brew config is in the edit to the original question.Noisemaker
Also, can you run brew doctor and ls -al $(which pod) for me?Chrysler
the output of brew doctor: github.com/zendevil/coca-install/blob/master/brew-doctor.out the output of ls -al $(which pod): github.com/zendevil/coca-install/blob/master/which-pod.outNoisemaker
This worked for me. In my case, I was running on a fresh copy of Big Sur, which had a Cocoapods.app installed. The app installed a symlink at /usr/local/bin/pod--version 1.5. Homebrew didn't want to overwrite it.Nasia
K
0

Restart Your Mac Run sudo gem install cocoapods Then

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

Ken answered 22/8, 2023 at 7:38 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.