cocoapods 安装失败

  • 完整报错
  • 尝试安装
  • 我的问题

使用 Alamofire 需要基于 CocoaPods,但是在尝试安装 CocoaPods 的过程中遇到了很多问题,捣鼓了很久都失败了,最后经群里大佬的点播才安装成功,其实有的时候问题的解决方案很简单,希望这篇博文可以帮到你。

完整报错

yusael@air ~ % sudo gem install -n /usr/local/bin cocoapods
Fetching cocoapods-trunk-1.6.0.gem
Fetching cocoapods-search-1.0.1.gem
Fetching cocoapods-plugins-1.0.0.gem
Fetching cocoapods-try-1.2.0.gem
Fetching cocoapods-downloader-1.5.1.gem
Fetching cocoapods-deintegrate-1.0.5.gem
Successfully installed cocoapods-try-1.2.0
Successfully installed cocoapods-trunk-1.6.0
Successfully installed cocoapods-search-1.0.1
Successfully installed cocoapods-plugins-1.0.0
Successfully installed cocoapods-downloader-1.5.1
Successfully installed cocoapods-deintegrate-1.0.5
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.15.4/ext/ffi_c
/System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/bin/ruby -I /Library/Ruby/Site/2.6.0 -r ./siteconf20211110-79554-472vcj.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.15.4/mkmf.logextconf failed, exit code 1Gem files will remain installed in /Library/Ruby/Gems/2.6.0/gems/ffi-1.15.4 for inspection.
Results logged to /Library/Ruby/Gems/2.6.0/extensions/universal-darwin-20/2.6.0/ffi-1.15.4/gem_make.out

尝试安装

步骤:先安装 homebrew,再更新 Ruby,再安装 cocoapods

注:很多网上博客要求安装 rvm,其实 rvm 并非必须,只是更新 Ruby 的一种方式

这里直接引用大佬的博客,参考如下:

  1. macOS 系统安装 Homebrew
  2. macOS 系统更新 Ruby
  3. macOS 系统重新 CocoaPods

我的问题

一般来说按照上面的流程,基本都可以完成安装。这里说一下我的问题,我的问题是 Ruby 版本过低,安装成功前我的版本是 2.6.3p62,在我将 Ruby 版本更新到 3.0.2_1 后,再执行:sudo gem install -n /usr/local/bin cocoapods 就安装成功啦!

这里主要一个问题是:通过 Homebrew 更新了最新的 Ruby,但是使用的时候不一定是最新的,所以导致安装失败。

(其实在上面引用的大佬的文章中有写配置最新的 Ruby 的环境变量,只是一开始没仔细看)

这里列出两个配置 Ruby 环境变量方法:

  • 方法 1:
echo 'export PATH="/usr/local/opt/ruby/bin:$PATH"' >> ~/.zshrc
  • 方法 2:
echo 'export PATH="/usr/local/opt/ruby/bin:$PATH"' >> ~/.bash_profile
source ~/.bash_profile

通过 ruby -v 查看 Ruby 版本是否更新,更新成最新的以后再去尝试安装一下吧…

cocoapods 安装失败 ERROR: Error installing cocoapods: ERROR: Failed to build gem native extension.相关推荐

  1. macOS安装 cocoapods1.9.1失败Failed to build gem native extension

    最近团队内升级cocoapods到1.9.0.原本我简单的以为执行sudo gem install cocoapods 来更新.万万没想到. 执行多次都是:ERROR: Error installin ...

  2. 安装gollum提示Failed to build gem native extension的解决

    安装gollum提示Failed to build gem native extension的解决 发表于2013 年 5 月 29 日 gollum是GitHub的一个开源Wiki引擎,老蔡准备用来 ...

  3. linner在ruby2.2.2下安装报错failed to build gem native extension,在1.9.2下安装又报错说nio4r说nio4r requires ruby ver

    安装linner时候,先是用的ruby2.2.2安装的,结果就报错说failed to build gem native extension,网上查到http://stackoverflow.com/ ...

  4. CocoaPods安装失败解决方法

    文章目录 出现场景 解决方法 出现场景 最新换了个512的大硬盘,重装了MacOS 10.15,安装Cocoapods时,出现以下错误 Building native extensions. This ...

  5. 系统升级到10.13之后cocoapods安装失败问题解决办法

    系统升级到最新版本(10.13.x)之后发现cocoapods更新失败了,重新安装之后也提示如下错误: $ pod setup -bash: /usr/local/bin/pod: /System/L ...

  6. Android Studio中 HAXM安装失败的问题(Intel HAXM installation failed. To install Intel HAXM follow the...)

    问题描述:安装Android Studio中 在最后一步出现  Intel HAXM installation failed. To install Intel HAXM follow the ins ...

  7. EAC安装失败解决方法(Copy file failed with 32)

    大家都知道育碧的一些游戏比如彩6,看门狗,龙珠格斗Z等,需要安装一个反作弊服务(Easy Anti Cheat)才能启动 安装失败有很多原因,其中一种是提示 " Copy file fail ...

  8. OBJC依赖库管理利器cocoapods 安装及使用详细图解

    cocoapods: github:https://github.com/CocoaPods/CocoaPods 官方网站:http://www.cocoapods.org/ 1.安装 RubyGem ...

  9. iOS CocoaPods安装教程

    前言介绍 在iOS项目中使用第三方类库可以说是非常常见的事,但是要正确地配置他们有时候是非常繁琐的事情,幸运的是CocoaPods是一个很好的解决方案. 什么是CocoaPods CocoaPods是 ...

最新文章

  1. kvm虚拟机--存储池配置梳理(转)
  2. City of Angels
  3. 设计模式--组合(Component)模式
  4. 【COCOS2DX隐藏IOS7状态栏】通过添加PLIST KEY隐藏IOS7状态栏
  5. IBASE timestamp conversion exit
  6. 配置java编译环境
  7. windows安装各版本python解释器和anaconda
  8. C语言和设计模式(代理模式)
  9. 数组模拟栈解决括号匹配
  10. python 词表里的词不符合_【NLP】词表太大怎么办—Adaptive softmax模型和代码解析...
  11. Microsoft Office 2016 简体中文Vl批量官方授权版镜像下载
  12. 自然语言处理之词袋模型Bag_of_words
  13. 三角形和矩形傅里叶变换_第3章傅立叶变换.doc
  14. Android 怎样默认打开便携式WIFI热点 M
  15. 【新书推荐】【2019.06】大局观从何而来
  16. 一语道破中国千年潜规则——每天懂一点人情世故
  17. Java反射机制实现与原理
  18. android刷机工具推荐,刷机也能如此轻松 Android一键刷机工具
  19. label 标签的巧妙使用
  20. 复制微信号并跳转到微信界面

热门文章

  1. 没人可以通过勤劳工作发财致富
  2. 使用mysql数据库与go进行交互
  3. vscode使用相关配置
  4. 安装netca_安装oracle 10g rac上的那些拦路虎
  5. 数据库sql创建标量值函数_使用JSON_VALUE()从JSON数据中提取标量值
  6. sql server 性能_如何在SQL Server中收集性能和系统信息
  7. JavaWeb过滤器的应用
  8. Flask详解(下篇)
  9. Vue的v-if与v-show的区别
  10. 【Python学习笔记】Coursera之PY4E学习笔记——String