正文
由于需要最新版本的Xcode工具,就升級(jí)了電腦系統(tǒng)到10.15.4 (19E287)。安裝了最新Xcode11.4安裝后發(fā)現(xiàn) cocoapods使用出現(xiàn)異常。需要重新安裝cocoapods.
安裝
因?yàn)镸ac電腦自帶Ruby環(huán)境,我們就只需打開終端直接安裝就可以了。如果出現(xiàn)ruby版本過低的情況可以先更新ruby。
1.查看當(dāng)前ruby版本
ruby -v
2.升級(jí)ruby環(huán)境(升級(jí)ruby需要借助rvm,需要先安裝rvm)
1.curl -L https://get.rvm.io | bash -s stable
2.source ~/.rvm/scripts/rvm
3.rvm -v
如果要升級(jí)rvm使用命令
rvm get stable
3.安裝ruby
1.rvm list known
結(jié)果為
# MRI Rubies
[ruby-]1.8.6[-p420]
[ruby-]1.8.7[-head] # security released on head
[ruby-]1.9.1[-p431]
[ruby-]1.9.2[-p330]
[ruby-]1.9.3[-p551]
[ruby-]2.0.0[-p648]
[ruby-]2.1[.10]
[ruby-]2.2[.10]
[ruby-]2.3[.8]
[ruby-]2.4[.6]
[ruby-]2.5[.5]
[ruby-]2.6[.3]
[ruby-]2.7[.0-preview1]
ruby-head
此時(shí)可以根據(jù)自己的需要安裝指定版本的ruby。
rvm install 2.6.3
本文相關(guān)操作是在ruby[ruby-]2.6[.3]完成的。
4.更換鏡像源(如果已經(jīng)處理可忽略此步驟)
sudo gem update --system
gem sources --remove https://rubygems.org/
gem sources --add https://gems.ruby-china.com/
查看更換結(jié)果
gem sources -l
*** CURRENT SOURCES ***
https://gems.ruby-china.com
5.安裝cocoapods 10.11后命令 之前的命令為(sudo gem install cocoapods)
sudo gem install -n /usr/local/bin cocoapods
此時(shí)如果出現(xiàn)以下錯(cuò)誤,原因是因?yàn)樵诎惭bxcode的時(shí)候保留了之前的版本,當(dāng)前系統(tǒng)上有兩個(gè)版本的xcode.
Building native extensions. This could take a while...
ERROR: Error installing cocoapods:
ERROR: Failed to build gem native extension.
current directory: /Users/gigaiot-sasai/.rvm/rubies/ruby-2.6.3/lib/ruby/gems/2.6.0/gems/ffi-1.12.2/ext/ffi_c
/Users/gigaiot-sasai/.rvm/rubies/ruby-2.6.3/bin/ruby -I /Users/gigaiot-sasai/.rvm/rubies/ruby-2.6.3/lib/ruby/site_ruby/2.6.0 -r ./siteconf20200423-788-10f5isy.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.
處理步驟
5.1 把最近安裝的xocde拖到中,注意名稱要為xcode默認(rèn)名。

5.2 終端執(zhí)行命令
sudo xcode-select -switch /Applications/Xcode.app/Contents/Developer
5.3 再次執(zhí)行安裝命令
sudo gem install -n /usr/local/bin cocoapods
安裝中...
Building native extensions. This could take a while...
Successfully installed ffi-1.12.2
Successfully installed ethon-0.12.0
Successfully installed typhoeus-1.3.1
Successfully installed cocoapods-core-1.9.1
Successfully installed xcodeproj-1.16.0
Successfully installed cocoapods-1.9.1
Parsing documentation for ffi-1.12.2
Installing ri documentation for ffi-1.12.2
Parsing documentation for ethon-0.12.0
Installing ri documentation for ethon-0.12.0
Parsing documentation for typhoeus-1.3.1
...
此時(shí)等待命令執(zhí)行完畢就可以了。
完成后搜索測(cè)試出現(xiàn)以下錯(cuò)誤。

終端執(zhí)行命令 即可
pod repo remove trunk

此時(shí)就可以正常搜索查詢檢索了。
總結(jié):
1.本文的場(chǎng)景是升級(jí)mac系統(tǒng).
2.安裝并保留了多個(gè)xcode.
3.pod search xx 命令長時(shí)間卡住沒有正確返回.
卸載cocopods 傳送門