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
To find if Cocoapods is installed or not run cmd (pod --version). if theresult is (Not Found) Pods is not installed.
If you try to install a gem through pre-installed Ruby, you've to use sudo by default witch is not a good practice. Another option is to install CocoaPods in your user-level directory by following instructions available on the Sudo-less installation section. I would suggest you install CocoaPods using brew .
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
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With