Bootstrap

更新pod时遇到(ERROR: Failed to build gem native extension.)的解决方案

一句正常的更新pod命令

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

正常情况下, 执行上面的命令 就可以直接升级成功,  升级成功万事大吉, 

反之就遇到下面的升级失败的情况!

➜  Ruby: 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 ./siteconf20200313-24412-3logr3.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

这个升级问题困扰了好多天,  可能是ruby的版本和最新的pod版本兼容性有问题, 所以必须先升级ruby, 才能升级pod成功, 且看下面:

方法是在stackoverflow找到的, 当然在安装过程中还需要解决一些其他的异常问题 (默认大家已经安装了  xcode-select)

1. 安装 rvm

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

如果可以安装成功并出现下列的提示则可以直接进行第二步

Upgrade of RVM in /Users/mengshun/.rvm/ is complete.

Thanks for installing RVM 🙏
Please consider donating to our open collective to help us maintain RVM.

👉  Donate: https://opencollective.com/rvm/donate

如果失败, 出现了下方的错误(报错内容 curl: (7) Failed to connect to raw.githubusercontent.com port 443: Operation timed out)

➜  Ruby: curl -L https://get.rvm.io | bash -s stable
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100   194  100   194    0     0    166      0  0:00:01  0:00:01 --:--:--   166
curl: (7) Failed to connect to raw.githubusercontent.com port 443: Connection refused
<
;