安裝CocoaPods遇到錯誤Failed to build gem native extension.

正常安裝CocoaPods只需要在終端輸入

sudo gem install 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.6.0/gems/ffi-1.15.5/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 ./siteconf20220121-65017-1lsof6r.rb extconf.rb
*** 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:546:in `block in try_link0'
    from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/tmpdir.rb:93:in `mktmpdir'
    from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/mkmf.rb:543:in `try_link0'
    from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/mkmf.rb:570:in `try_link'
    from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/mkmf.rb:672:in `try_ldflags'
    from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/mkmf.rb:1832:in `pkg_config'
    from extconf.rb:9: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.5/mkmf.log

extconf failed, exit code 1

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

接下來你要做的就是

  • 安裝RVM
curl -L https://get.rvm.io | bash -s stable
  • 安裝Ruby 2.6
rvm install ruby-2.6

如果你是M1芯片的電腦,會出現(xiàn)rvm command not found,此時你退出終端程序助析,在Finder里找到終端缠导,右鍵選擇顯示簡介反砌,勾選使用Rosetta打開重新執(zhí)行這個命令就可以了

如果遇到了下面的錯誤

Error running 'requirements_osx_brew_libs_install autoconf automake libtool pkg-config coreutils libyaml libksba readline zlib openssl@1.1',
please read /Users/fandong/.rvm/log/1642813404_ruby-2.6.6/package_install_autoconf_automake_libtool_pkg-config_coreutils_libyaml_libksba_readline_zlib_openssl@1.1.log
Requirements installation failed with status: 1.

我們挨個安裝這些依賴

brew install autoconf

但是你可能會遇到

Warning: No available formula with the name "automake".
==> Searching for similarly named formulae...
Error: No similarly named formulae found.
==> Searching for a previously deleted formula (in the last month)...
Error: No previously deleted formula found.
==> Searching taps on GitHub...
Error: No formulae found in taps.

你需要

rm -rf /usr/local/Homebrew/Library/Taps/homebrew/homebrew-core;
brew update

再來執(zhí)行

brew install autoconf
brew install automake
brew install libtool
brew install pkg-config
brew install coreutils
brew install libyaml
brew install libksba
brew install readline
brew install zlib
brew install openssl

再來執(zhí)行

rvm install ruby-2.6

然后再來執(zhí)行剛開始的

sudo gem install cocoapods
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
  • 序言:七十年代末欣舵,一起剝皮案震驚了整個濱河市止剖,隨后出現(xiàn)的幾起案子亮靴,更是在濱河造成了極大的恐慌馍盟,老刑警劉巖,帶你破解...
    沈念sama閱讀 216,372評論 6 498
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件茧吊,死亡現(xiàn)場離奇詭異贞岭,居然都是意外死亡八毯,警方通過查閱死者的電腦和手機(jī),發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 92,368評論 3 392
  • 文/潘曉璐 我一進(jìn)店門曹步,熙熙樓的掌柜王于貴愁眉苦臉地迎上來宪彩,“玉大人,你說我怎么就攤上這事讲婚∧蚩祝” “怎么了?”我有些...
    開封第一講書人閱讀 162,415評論 0 353
  • 文/不壞的土叔 我叫張陵筹麸,是天一觀的道長活合。 經(jīng)常有香客問我,道長物赶,這世上最難降的妖魔是什么白指? 我笑而不...
    開封第一講書人閱讀 58,157評論 1 292
  • 正文 為了忘掉前任,我火速辦了婚禮酵紫,結(jié)果婚禮上告嘲,老公的妹妹穿的比我還像新娘。我一直安慰自己奖地,他們只是感情好橄唬,可當(dāng)我...
    茶點故事閱讀 67,171評論 6 388
  • 文/花漫 我一把揭開白布。 她就那樣靜靜地躺著参歹,像睡著了一般仰楚。 火紅的嫁衣襯著肌膚如雪。 梳的紋絲不亂的頭發(fā)上犬庇,一...
    開封第一講書人閱讀 51,125評論 1 297
  • 那天僧界,我揣著相機(jī)與錄音,去河邊找鬼臭挽。 笑死捂襟,一個胖子當(dāng)著我的面吹牛,可吹牛的內(nèi)容都是我干的欢峰。 我是一名探鬼主播葬荷,決...
    沈念sama閱讀 40,028評論 3 417
  • 文/蒼蘭香墨 我猛地睜開眼,長吁一口氣:“原來是場噩夢啊……” “哼赤赊!你這毒婦竟也來了闯狱?” 一聲冷哼從身側(cè)響起,我...
    開封第一講書人閱讀 38,887評論 0 274
  • 序言:老撾萬榮一對情侶失蹤抛计,失蹤者是張志新(化名)和其女友劉穎哄孤,沒想到半個月后,有當(dāng)?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體吹截,經(jīng)...
    沈念sama閱讀 45,310評論 1 310
  • 正文 獨居荒郊野嶺守林人離奇死亡瘦陈,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點故事閱讀 37,533評論 2 332
  • 正文 我和宋清朗相戀三年凝危,在試婚紗的時候發(fā)現(xiàn)自己被綠了。 大學(xué)時的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片晨逝。...
    茶點故事閱讀 39,690評論 1 348
  • 序言:一個原本活蹦亂跳的男人離奇死亡蛾默,死狀恐怖,靈堂內(nèi)的尸體忽然破棺而出捉貌,到底是詐尸還是另有隱情支鸡,我是刑警寧澤,帶...
    沈念sama閱讀 35,411評論 5 343
  • 正文 年R本政府宣布趁窃,位于F島的核電站牧挣,受9級特大地震影響,放射性物質(zhì)發(fā)生泄漏醒陆。R本人自食惡果不足惜瀑构,卻給世界環(huán)境...
    茶點故事閱讀 41,004評論 3 325
  • 文/蒙蒙 一、第九天 我趴在偏房一處隱蔽的房頂上張望刨摩。 院中可真熱鬧寺晌,春花似錦、人聲如沸澡刹。這莊子的主人今日做“春日...
    開封第一講書人閱讀 31,659評論 0 22
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽像屋。三九已至怕犁,卻和暖如春边篮,著一層夾襖步出監(jiān)牢的瞬間己莺,已是汗流浹背。 一陣腳步聲響...
    開封第一講書人閱讀 32,812評論 1 268
  • 我被黑心中介騙來泰國打工戈轿, 沒想到剛下飛機(jī)就差點兒被人妖公主榨干…… 1. 我叫王不留凌受,地道東北人。 一個月前我還...
    沈念sama閱讀 47,693評論 2 368
  • 正文 我出身青樓思杯,卻偏偏與公主長得像胜蛉,于是被迫代替她去往敵國和親。 傳聞我的和親對象是個殘疾皇子色乾,可洞房花燭夜當(dāng)晚...
    茶點故事閱讀 44,577評論 2 353

推薦閱讀更多精彩內(nèi)容