Cocoapods升级报错Error installing cocoapods: Failed to build gem native extension

1,935 阅读1分钟

很长一段时间未用cocoapods,更新不了最新的三方库,要求升级cocoapods。

1、升级Ruby环境

sudo gem update --system

2、更新cocoapods

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

结果报错:

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.3.0/gems/ffi-1.12.2/ext/ffi_c
/System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/bin/ruby -r ./siteconf20200309-13044-14m1r7i.rb extconf.rb
mkmf.rb can't find header files for ruby at /System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/lib/ruby/include/ruby.h

extconf failed, exit code 1

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

各种查资料,折腾一天 ,终于解决:

open /Library/Developer/CommandLineTools/Packages/macOS_SDK_headers_for_macOS_10.14.pkg

安装成功后继续运行:

sudo gem install -n /usr/local/bin cocoapods
Building native extensions. This could take a while...
Successfully installed ffi-1.14.2
Successfully installed ethon-0.12.0
Successfully installed typhoeus-1.4.0
Successfully installed public_suffix-4.0.6
Successfully installed concurrent-ruby-1.1.8
Successfully installed addressable-2.7.0
Successfully installed activesupport-5.2.4.5
Successfully installed cocoapods-core-1.10.1
Successfully installed cocoapods-1.10.1
Parsing documentation for ffi-1.14.2
Installing ri documentation for ffi-1.14.2
Parsing documentation for ethon-0.12.0
Installing ri documentation for ethon-0.12.0
Parsing documentation for typhoeus-1.4.0
Installing ri documentation for typhoeus-1.4.0
Parsing documentation for public_suffix-4.0.6
Installing ri documentation for public_suffix-4.0.6
Parsing documentation for concurrent-ruby-1.1.8
Installing ri documentation for concurrent-ruby-1.1.8
Parsing documentation for addressable-2.7.0
Installing ri documentation for addressable-2.7.0
Parsing documentation for activesupport-5.2.4.5
Installing ri documentation for activesupport-5.2.4.5
Parsing documentation for cocoapods-core-1.10.1
Installing ri documentation for cocoapods-core-1.10.1
Parsing documentation for cocoapods-1.10.1
Installing ri documentation for cocoapods-1.10.1
Done installing documentation for ffi, ethon, typhoeus, public_suffix, concurrent-ruby, addressable, activesupport, cocoapods-core, cocoapods after 35 seconds
9 gems installed

搞定!