安装(更新)cocoapods失败:ERROR: Failed to build gem native extension.

新电脑,安装cocoapods的时候报错,报错截图如下:

安装cocoapods报错.png

安装失败好久了,一直不是必须要安装pod,所以没有在意没去解决,今天实在要安装pod复现个问题,终于动手搜了下这个报错,试了下这个博客的解决方式,搞定。
报错原因猜测是ruby的版本和最新的pod版本兼容性有问题, 所以必须先升级ruby。
解决步骤:

  1. 安装 rvm
    curl -L https://get.rvm.io | bash -s stable
    安装成功会出现下图提示:

    安装rvn成功.png

    如果失败, 出现了这样的错误(报错内容 curl: (7) Failed to connect to raw.githubusercontent.com port 443: Operation timed out),需要执行下列指令:
    sudo gem install redis
    然后继续执行rvm的安装命令:
    curl -L https://get.rvm.io | bash -s stable
    如果还是报 443 错误, 那就等一会再执行, 多次重试总会成功的。

  2. 安装 ruby 2.6
    rvm install ruby-2.6
    运行后:

 ✘ ryhnsong@RyhndeMacBook-Pro  ~  rvm install ruby-2.6
Searching for binary rubies, this might take some time.
No binary rubies available for: osx/11.5/x86_64/ruby-2.6.6.
Continuing with compilation. Please read 'rvm help mount' to get more information on binary rubies.
Checking requirements for osx.
Updating certificates bundle '/usr/local/etc/openssl@1.1/cert.pem'
Requirements installation successful.
Installing Ruby from source to: /Users/ryhnsong/.rvm/rubies/ruby-2.6.6, this may take a while depending on your cpu(s)...
ruby-2.6.6 - #downloading ruby-2.6.6, this may take a while depending on your connection...
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100 13.4M  100 13.4M    0     0  11567      0  0:20:22  0:20:22 --:--:-- 16887
ruby-2.6.6 - #extracting ruby-2.6.6 to /Users/ryhnsong/.rvm/src/ruby-2.6.6 - please wait
ruby-2.6.6 - #configuring - please wait

ruby-2.6.6 - #post-configuration - please wait
ruby-2.6.6 - #compiling - please wait
ruby-2.6.6 - #installing - please wait
ruby-2.6.6 - #making binaries executable - please wait
ruby-2.6.6 - #downloading rubygems-3.0.9
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100  865k  100  865k    0     0  25855      0  0:00:34  0:00:34 --:--:-- 10055
No checksum for downloaded archive, recording checksum in user configuration.
ruby-2.6.6 - #extracting rubygems-3.0.9 - please wait
ruby-2.6.6 - #removing old rubygems - please wait
ruby-2.6.6 - #installing rubygems-3.0.9 - please wait
ruby-2.6.6 - #gemset created /Users/ryhnsong/.rvm/gems/ruby-2.6.6@global
ruby-2.6.6 - #importing gemset /Users/ryhnsong/.rvm/gemsets/global.gems - please wait
ruby-2.6.6 - #generating global wrappers - please wait
ruby-2.6.6 - #gemset created /Users/ryhnsong/.rvm/gems/ruby-2.6.6
ruby-2.6.6 - #importing gemsetfile /Users/ryhnsong/.rvm/gemsets/default.gems evaluated to empty gem list
ruby-2.6.6 - #generating default wrappers - please wait
ruby-2.6.6 - #adjusting #shebangs for (gem irb erb ri rdoc testrb rake).
Install of ruby-2.6.6 - #complete
Ruby was built without documentation, to build it run: rvm docs generate-ri

设置rvm使用版本:
rvm use ruby-2.6.6
设置rvm默认使用版本:
rvm --default use 2.6.6

  1. 重新安装cocoapods:
    sudo gem install cocoapods
    安装成功:
Fetching concurrent-ruby-1.1.9.gem
Fetching i18n-1.8.11.gem
Fetching tzinfo-2.0.4.gem
Fetching zeitwerk-2.5.1.gem
Fetching activesupport-6.1.4.1.gem
Fetching fuzzy_match-2.0.4.gem
Fetching nap-1.1.0.gem
Fetching httpclient-2.8.3.gem
Fetching typhoeus-1.4.0.gem
Fetching netrc-0.11.0.gem
Fetching algoliasearch-1.27.5.gem
Fetching ffi-1.15.4.gem
Fetching ethon-0.15.0.gem
Fetching public_suffix-4.0.6.gem
Fetching addressable-2.8.0.gem
Fetching cocoapods-core-1.11.2.gem
Fetching cocoapods-plugins-1.0.0.gem
Fetching claide-1.0.3.gem
Fetching cocoapods-deintegrate-1.0.5.gem
Fetching cocoapods-try-1.2.0.gem
Fetching cocoapods-downloader-1.5.1.gem
Fetching cocoapods-search-1.0.1.gem
Fetching cocoapods-trunk-1.6.0.gem
Fetching molinillo-0.8.0.gem
Fetching atomos-0.1.3.gem
Fetching rexml-3.2.5.gem
Fetching CFPropertyList-3.0.5.gem
Fetching escape-0.0.4.gem
Fetching colored2-3.1.2.gem
Fetching fourflusher-2.3.1.gem
Fetching nanaimo-0.3.0.gem
Fetching gh_inspector-1.1.3.gem
Fetching xcodeproj-1.21.0.gem
Fetching ruby-macho-2.5.1.gem
Fetching cocoapods-1.11.2.gem
Successfully installed concurrent-ruby-1.1.9
Successfully installed i18n-1.8.11
Successfully installed tzinfo-2.0.4
Successfully installed zeitwerk-2.5.1
Successfully installed activesupport-6.1.4.1
Successfully installed nap-1.1.0
Successfully installed fuzzy_match-2.0.4
Successfully installed httpclient-2.8.3
A new major version is available for Algolia! Please now use the https://rubygems.org/gems/algolia gem to get the latest features.
Successfully installed algoliasearch-1.27.5
Building native extensions. This could take a while...
Successfully installed ffi-1.15.4
Successfully installed ethon-0.15.0
Successfully installed typhoeus-1.4.0
Successfully installed netrc-0.11.0
Successfully installed public_suffix-4.0.6
Successfully installed addressable-2.8.0
Successfully installed cocoapods-core-1.11.2
Successfully installed claide-1.0.3
Successfully installed cocoapods-deintegrate-1.0.5
Successfully installed cocoapods-downloader-1.5.1
Successfully installed cocoapods-plugins-1.0.0
Successfully installed cocoapods-search-1.0.1
Successfully installed cocoapods-trunk-1.6.0
Successfully installed cocoapods-try-1.2.0
Successfully installed molinillo-0.8.0
Successfully installed atomos-0.1.3
Successfully installed rexml-3.2.5
Successfully installed CFPropertyList-3.0.5
Successfully installed colored2-3.1.2
Successfully installed nanaimo-0.3.0
Successfully installed xcodeproj-1.21.0
Successfully installed escape-0.0.4
Successfully installed fourflusher-2.3.1
Successfully installed gh_inspector-1.1.3
Successfully installed ruby-macho-2.5.1
Successfully installed cocoapods-1.11.2
Parsing documentation for concurrent-ruby-1.1.9
Installing ri documentation for concurrent-ruby-1.1.9
Parsing documentation for i18n-1.8.11
Installing ri documentation for i18n-1.8.11
Parsing documentation for tzinfo-2.0.4
Installing ri documentation for tzinfo-2.0.4
Parsing documentation for zeitwerk-2.5.1
Installing ri documentation for zeitwerk-2.5.1
Parsing documentation for activesupport-6.1.4.1
Installing ri documentation for activesupport-6.1.4.1
Parsing documentation for nap-1.1.0
Installing ri documentation for nap-1.1.0
Parsing documentation for fuzzy_match-2.0.4
Installing ri documentation for fuzzy_match-2.0.4
Parsing documentation for httpclient-2.8.3
Installing ri documentation for httpclient-2.8.3
Parsing documentation for algoliasearch-1.27.5
Installing ri documentation for algoliasearch-1.27.5
Parsing documentation for ffi-1.15.4
Installing ri documentation for ffi-1.15.4
Parsing documentation for ethon-0.15.0
Installing ri documentation for ethon-0.15.0
Parsing documentation for typhoeus-1.4.0
Installing ri documentation for typhoeus-1.4.0
Parsing documentation for netrc-0.11.0
Installing ri documentation for netrc-0.11.0
Parsing documentation for public_suffix-4.0.6
Installing ri documentation for public_suffix-4.0.6
Parsing documentation for addressable-2.8.0
Installing ri documentation for addressable-2.8.0
Parsing documentation for cocoapods-core-1.11.2
Installing ri documentation for cocoapods-core-1.11.2
Parsing documentation for claide-1.0.3
Installing ri documentation for claide-1.0.3
Parsing documentation for cocoapods-deintegrate-1.0.5
Installing ri documentation for cocoapods-deintegrate-1.0.5
Parsing documentation for cocoapods-downloader-1.5.1
Installing ri documentation for cocoapods-downloader-1.5.1
Parsing documentation for cocoapods-plugins-1.0.0
Installing ri documentation for cocoapods-plugins-1.0.0
Parsing documentation for cocoapods-search-1.0.1
Installing ri documentation for cocoapods-search-1.0.1
Parsing documentation for cocoapods-trunk-1.6.0
Installing ri documentation for cocoapods-trunk-1.6.0
Parsing documentation for cocoapods-try-1.2.0
Installing ri documentation for cocoapods-try-1.2.0
Parsing documentation for molinillo-0.8.0
Installing ri documentation for molinillo-0.8.0
Parsing documentation for atomos-0.1.3
Installing ri documentation for atomos-0.1.3
Parsing documentation for rexml-3.2.5
Installing ri documentation for rexml-3.2.5
Parsing documentation for CFPropertyList-3.0.5
Installing ri documentation for CFPropertyList-3.0.5
Parsing documentation for colored2-3.1.2
Installing ri documentation for colored2-3.1.2
Parsing documentation for nanaimo-0.3.0
Installing ri documentation for nanaimo-0.3.0
Parsing documentation for xcodeproj-1.21.0
Installing ri documentation for xcodeproj-1.21.0
Parsing documentation for escape-0.0.4
Installing ri documentation for escape-0.0.4
Parsing documentation for fourflusher-2.3.1
Installing ri documentation for fourflusher-2.3.1
Parsing documentation for gh_inspector-1.1.3
Installing ri documentation for gh_inspector-1.1.3
Parsing documentation for ruby-macho-2.5.1
Installing ri documentation for ruby-macho-2.5.1
Parsing documentation for cocoapods-1.11.2
Installing ri documentation for cocoapods-1.11.2
Done installing documentation for concurrent-ruby, i18n, tzinfo, zeitwerk, activesupport, nap, fuzzy_match, httpclient, algoliasearch, ffi, ethon, typhoeus, netrc, public_suffix, addressable, cocoapods-core, claide, cocoapods-deintegrate, cocoapods-downloader, cocoapods-plugins, cocoapods-search, cocoapods-trunk, cocoapods-try, molinillo, atomos, rexml, CFPropertyList, colored2, nanaimo, xcodeproj, escape, fourflusher, gh_inspector, ruby-macho, cocoapods after 36 seconds
35 gems installed

备注:解决方案完全参考这个博客,感谢这位博主的分享!

©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 211,290评论 6 491
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 90,107评论 2 385
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 156,872评论 0 347
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 56,415评论 1 283
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 65,453评论 6 385
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 49,784评论 1 290
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 38,927评论 3 406
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 37,691评论 0 266
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 44,137评论 1 303
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 36,472评论 2 326
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 38,622评论 1 340
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 34,289评论 4 329
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 39,887评论 3 312
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 30,741评论 0 21
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 31,977评论 1 265
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 46,316评论 2 360
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 43,490评论 2 348

推荐阅读更多精彩内容