Error installing CocoaPods - macOS BigSur

25.8k views Asked by At

I'm learning how to program, and I am trying to install Cocoapods, but I'm getting an error with sudo gem install cocoapods.

This is what I get:

    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.6.0/gems/ffi-1.13.1/ext/ffi_c
/System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/bin/ruby -I /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0 -r ./siteconf20201006-615-fryp4a.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
    --without-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=/System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/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
/System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/mkmf.rb:467:in `try_do': The compiler failed to generate an executable file. (RuntimeError)
You have to install development tools first.
    from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/mkmf.rb:585:in `block in try_compile'
    from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/mkmf.rb:534:in `with_werror'
    from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/mkmf.rb:585:in `try_compile'
    from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/mkmf.rb:1109:in `block in have_header'
    from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/mkmf.rb:959:in `block in checking_for'
    from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/mkmf.rb:361:in `block (2 levels) in postpone'
    from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/mkmf.rb:331:in `open'
    from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/mkmf.rb:361:in `block in postpone'
    from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/mkmf.rb:331:in `open'
    from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/mkmf.rb:357:in `postpone'
    from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/mkmf.rb:958:in `checking_for'
    from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/mkmf.rb:1108: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:

  /Library/Ruby/Gems/2.6.0/extensions/universal-darwin-20/2.6.0/ffi-1.13.1/mkmf.log

extconf failed, exit code 1

Gem files will remain installed in /Library/Ruby/Gems/2.6.0/gems/ffi-1.13.1 for inspection.
Results logged to /Library/Ruby/Gems/2.6.0/extensions/universal-darwin-20/2.6.0/ffi-1.13.1/gem_make.out

I know that there is a line where it says "You have to install development tools first", and at first it was true. I then installed the Xcode command line tools (I had to do it manually downloading it from Apple Developer because the xcode-select --install line didn't work), and tried to install cocoapods again. But I'm getting the same error, even after rebooting.

It also has the route for the log, and this is what it says:

package configuration for libffi is not found
"xcrun clang -o conftest -I/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.15.sdk/System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/include/ruby-2.6.0/universal-darwin20 -I/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.15.sdk/System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/include/ruby-2.6.0/ruby/backward -I/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.15.sdk/System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/include/ruby-2.6.0 -I. -D_XOPEN_SOURCE -D_DARWIN_C_SOURCE -D_DARWIN_UNLIMITED_SELECT -D_REENTRANT    -g -Os -pipe -DHAVE_GCC_ATOMIC_BUILTINS -DUSE_FFI_CLOSURE_ALLOC conftest.c  -L. -L/System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib -L. -L/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX11.0.Internal.sdk/usr/local/lib     -lruby.2.6   "
In file included from conftest.c:1:
In file included from /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.15.sdk/System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/include/ruby-2.6.0/ruby.h:33:
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.15.sdk/System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/include/ruby-2.6.0/ruby/ruby.h:24:10: fatal error: 'ruby/config.h' file not found
#include "ruby/config.h"
         ^~~~~~~~~~~~~~~
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.15.sdk/System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/include/ruby-2.6.0/ruby/ruby.h:24:10: note: did not find header 'config.h' in framework 'ruby' (loaded from '/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/System/Library/Frameworks')
1 error generated.
checked program was:
/* begin */
1: #include "ruby.h"
2: 
3: int main(int argc, char **argv)
4: {
5:   return 0;
6: }
/* end */

So, I'm stuck. I'm currently using macOS Big Sur Beta 9, and Xcode 12.0.1 (non-beta).

11

There are 11 answers

3
Max Sanchez On BEST ANSWER

Well, today I was able to finally install Cocoapods successfully, but it was a weird process.

When learning people usually tell you to stay away from betas, and while I was in the stable AppStore-version of Xcode, I was running Big Sur B9; and that could have been the problem. I completely uninstalled Xcode 12.0.1 and then downloaded from Apple Developer Xcode 12.2 beta. I then downloaded and installed the command line tools also for 12.2 beta, and ran again the cocoapods installation in Terminal… and voila!

After installing and running Xcode beta I was able to install and now works fine. Maybe when BigSur becomes public this will be solved? Because not everyone needs or has to run Xcode beta versions.

0
Victor Dias On

I've faced the exact same issue

$ sudo gem install cocoapods
...
checking for ffi.h... *** extconf.rb failed ***
Could not create Makefile due to some reason, probably lack of necessary
libraries and/or headers.
...

Fixed by upgrading ruby version to 2.7.2. Credits for https://stackoverflow.com/a/65033418/4982169

I use rbenv to manage ruby versions.

0
Nguyễn Tùng On

update the latest version ruby: https://www.delftstack.com/howto/ruby/update-ruby-version-in-macos/ and check version ruby:

ruby -v

and then:

sudo gem install cocoapods
0
Mohit On

This worked for me:

https://github.com/CocoaPods/CocoaPods/issues/10286#issuecomment-747512270

Quote:

  • Download Command Line Tools 11.5 from Apple Developer Downloads
  • sudo rm -rf /Library/Developer/CommandLineTools
  • Install Command Line Tools from .dmg/.pkg
  • sudo xcode-select --switch /Library/Developer/CommandLineTools
  • [sudo] gem install [--user-install] cocoapods
  • sudo xcode-select --switch /Applications/Xcode.app/Contents/Developer
1
user3305074 On

Above sols. might or might not work for everyone, but just make sure to cross check command line tools.. It must be set and not blank.

enter image description here

0
Hari Narayanan On

or if you already installed the cocoa pods just run

brew install cocoapods

after its showing some warning message

Warning: cocoapods 1.10.1 is already installed, it's just not linked.

To link this version, run: brew link cocoapods or

brew link --overwrite cocoapods

it was really helpful for me. thank you

0
SteveCaine On

Switching the default Xcode command-line tools from version 12.4 to 11.7 solved this problem for me.

I have both Xcode versions installed on Catalina (10.15.7), so I made the switch using Xcode Preferences (Locations/Command Line Tools:), selecting "Xcode 11.7" in the popup menu. Then I quit Xcode and ran the install command again:

sudo gem install cocoapods

Where before I was getting the same "missing header" error, now the install proceeded without incident.

Command-line tools can be installed separately, without having to install Xcode itself. Then you would use Terminal to switch versions. The path to the current default tools is returned by

xcode-select -p

and switching versions is done using

sudo xcode-select -s {path-to-tools} 

After installing CocoaPods I switched back to the latest command-line tools and did 'pod install' on one of my current projects, which succeeded without incident. So the earlier version seems necessary only for CocoaPods install, not its operation.

2
Jongwook Choi On

XCode's ruby framework appears to have a problem. Reinstall Xcode.app cleanly with the latest version and running xcode-select --install or --select did not work for me.

This is how I managed to make it run with XCode 12.2 and Catalina (10.15.7): https://stackoverflow.com/a/65481787/1534182

TL;DR)

cd /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX11.1.sdk/System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/include/ruby-2.6.0/ruby
ln -sf ../../../../Headers/ruby/config.h

cd /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX11.1.sdk/System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/include/ruby-2.6.0
ln -sf universal-darwin20 universal-darwin19

(edit fixed typo in symlink)

1
Mikolaj On

I had the same issue (Catalina 10.15.7 & Xcode 12.3).

I used homebrew instead of the gem:

brew install cocoapods
0
duckbox On

I had the same error over and over again and tried several ways to fix it, including many described here, with no success.

As explained here: https://developer.apple.com/forums/thread/668456 , depending on some aspects this might work for you as it did for me!

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

Apparently the later cocoapads versions,specially latest (1.11.2) wont work!

1
Teddichiiwa On

Solve by upgrading Xcode to 12.2 on macOS Big Sur.

Then run:

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

Wasted 5 hours because I thought it was a gem's issue.

Success install cocoapods