2021 升級Big Sur后cocoapods的安裝方法

一、 概要

CocoaPods可以用來方便的統一管理這些第三方庫
初衷:因為mac系統更新到10.13.5, cocoapod失效了要重新安裝。因此寫下該博文方便日后自己查看

二、安裝

步驟
1,檢查是否已安裝rvm,若安裝了跳過,未安裝的話先安裝
2,檢查ruby是否最新版,安裝最新版的ruby(為了匹配mac系統)
3,安裝cocoapod 第三方苦管理工具

概念

rvm : Ruby Version Manager 安裝和空置Ruby版本的工具
Ruby: 先理解為一種腳本語言,作為安裝cocoapod的鏡像
Cocoapod : 類庫管理工具,管理第三方庫

第一步,首先要檢查Mac是否安裝了rvm。打開終端,輸入指令

rvm -v

image.png

step1 :安裝rvm

curl -L get.rvm.io | bash -s stable

#安裝rvm出現的坑報SSL_ERROR_SYSCALL in connection to raw.githubusercontent.com:443,請使用國內的homebrew后重新走上一步安裝rvm。
/bin/zsh -c "$(curl -fsSL https://gitee.com/cunkai/HomebrewCN/raw/master/Homebrew.sh)"

step2 :指定源

source ~/.rvm/scripts/rvm

step3 :查看版本確認是否安裝成功

rvm -v

//會出現類似這種的  表示安裝成功
rvm 1.29.3 (latest) by Michal Papis, Piotr Kuczynski, Wayne E. Seguin [https://rvm.io]

Step 4: 列出所有指定源里的ruby版本

rvm list known

//出現 以下的內容
[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[.7]
[ruby-]2.3[.4]
[ruby-]2.4[.1]
ruby-head

第二步,用rvm安裝ruby環境

Step1:查看當前的ruby的版本

ruby -v

//當前版本是2.33,上面查詢最新的版本是2.4.1
ruby 2.3.3p222 (2016-11-21 revision 56859) [universal.x86_64-darwin17]

Step2:升級最新版的ruby

rvm install 2.4.1  

Step3:這里在升級ruby的時候失敗的話 可能是gem太老了可以嘗試用如下命令升級 gem

sudo gem update --system

Step4:檢查ruby源并移除

1、移除現有Ruby默認源    gem sources --remove https://rubygems.org/
2、使用新的源    gem sources -a https://gems.ruby-china.com/
這里注意:
以前的https://ruby.taobao.org/ 被拋棄了
以前的https://gems.ruby-china.org/ 域名已更換成https://gems.ruby-china.com/
3.驗證新源是否替換成功    gem sources -l

*** CURRENT SOURCES ***
https://gems.ruby-china.com/

代表替換成功!!

需要注意以下??

image.png

第三步,安裝CocoaPods

sudo 表示管理員執行指令,需要輸入密碼的
Step1:安裝cocoapods

OS X 10.11之前系統的安裝cocoapods 指令:
$ sudo gem install cocoapods

OS X 10.11以后系統的安裝cocoapods 指令:
$ sudo gem install -n /usr/local/bin cocoa pods

Step2:初始化cocoapods

$ pod setup

#如果pod setup的時候,提示pod: command not found 
$ sudo gem install -n /usr/local/bin cocoapods /
$ sudo chmod +rx /usr/local/bin

#setup結束后,Unable to find a pod with name, author, summary, or description matching `afnetworking`
$ pod repo remove master
$ cd ~/.cocoapods/repos
$ git clone --depth 1 https://github.com/CocoaPods/Specs.git master
$ rm ~/Library/Caches/CocoaPods/search_index.json
$ pod search afnetworking

Step3:更新gem

//再更新一次吧
sudo gem update --system

Step4:測試一下是否安裝成功

pod --version
1.5.3 //暫時最新版本

pod search afnetworking

-> AFNetworking (3.2.1)
   A delightful iOS and OS X networking framework.
   pod 'AFNetworking', '~> 3.2.1'
   - Homepage: https://github.com/AFNetworking/AFNetworking
   - Source:   https://github.com/AFNetworking/AFNetworking.git
   - Versions: 3.2.1, 3.2.0, 3.1.0, 3.0.4, 3.0.3, 3.0.2, 3.0.1, 3.0.0,
   3.0.0-beta.3, 3.0.0-beta.2, 3.0.0-beta.1, 2.6.3, 2.6.2, 2.6.1, 2.6.0, 2.5.4,
   2.5.3, 2.5.2, 2.5.1, 2.5.0, 2.4.1, 2.4.0, 2.3.1, 2.3.0, 2.2.4, 2.2.3, 2.2.2,
   2.2.1, 2.2.0, 2.1.0, 2.0.3, 2.0.2, 2.0.1, 2.0.0, 2.0.0-RC3, 2.0.0-RC2,
   2.0.0-RC1, 1.3.4, 1.3.3, 1.3.2, 1.3.1, 1.3.0, 1.2.1, 1.2.0, 1.1.0, 1.0.1,
   1.0, 1.0RC3, 1.0RC2, 1.0RC1, 0.10.1, 0.10.0, 0.9.2, 0.9.1, 0.9.0, 0.7.0,
   0.5.1 [master repo]
   - Subspecs:
     - AFNetworking/Serialization (3.2.1)
     - AFNetworking/Security (3.2.1)
     - AFNetworking/Reachability (3.2.1)
     - AFNetworking/NSURLSession (3.2.1)
     - AFNetworking/UIKit (3.2.1)

安裝 oh my zsh

// 習慣使用oh my zsh,方便知道成功或失敗狀態
$ sh -c "$(curl -fsSL https://raw.github.com/robbyrussell/oh-my-zsh/master/tools/install.sh)"

第四,常見的安裝錯誤

  • Unable to find a pod with name, author, summary, or description matching
    解決方法:
rm ~/Library/Caches/CocoaPods/search_index.json (第一步)

pod search afnetworking (第二步)
  • can't find gem cocoapods (>= 0.a)
    解決方法:
1: sudo gem uninstall cocoapods

2: gem install cocoapods

3: pod install
  • [!] An error occurred while performing [Git](http://lib.csdn.net/base/git) pull on repo master.
    解決方法:
sudo rm -fr ~/.cocoapods/repos/master
然后再: pod setup
  • Creating search index for spec repo 'master'..
當pod search 回車后出現以下, 只需要等就可以了, 第一次的時候是會等得比較久一些
  • Requirements installation failed with status: 1.
    這是安裝ruby的時候出現的問題
    解決方法:
brew update
rvm get head
rvm install 2.3
  • /usr/local/etc/openssl/cert.pem
    這是更新ruby的時候,報openssl錯的時候
    解決方法:
rvm pkg install openssl
rvm install 2.0.0 
rvm use 2.0.0 --default
  • can't find gem cocoapods (>= 0.a) (Gem::GemNotFoundException)
    解決方法:(可嘗試下。如果不行請再百度)
which pod  //現找一下 pod的路徑
sudo rm -rf /usr/local/bin/pod  //刪除目錄下的文件
gem list  //獲取gem
gem uninstall cocoapods -v 0.39.0  //移除程序包
gem uninstall cocoapods-core -v 0.39.0

sudo gem install cocoapods //重新安裝cocoapod
pod --version
  • 當安裝比較卡想退出安裝: Ctrl + C鍵

  • /Library/Ruby/Site/2.0.0/rubygems.rb:270:in find_spec_for_exe': can't find gem cocoapods (>= 0.a) (Gem::GemNotFoundException) from /Library/Ruby/Site/2.0.0/rubygems.rb:298:inactivate_bin_path' from /usr/local/bin/pod:22:in `<main>'
    解決方法:

一、可能因為ruby版本過低導致,請先升級ruby到最新版本,在重新安裝pod

二、如果更新了ruby為最新版本也不行,請走下一步(更新ruby上文能查閱)
1.gem install cocoapods
2.pod install
  • 升級macOS High Sierra后cocoapods不能使用的解決辦法
sudo gem update --system  //升級ruby
sudo gem install -n /usr/local/bin cocoapods  //重新安裝cocoapods

當以后更新了mac系統版本,如果出現cocoapod出現問題。更新ruby最新版本。然后再重新安裝cocoapod,最后走一次pod setup就可以。
#重裝command line tools,再執行安裝homebrew指令

removing the old tools ($ rm -rf /Library/Developer/CommandLineTools)
install xcode command line tools again ($ xcode-select --install).
/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
  • pod install提示找不到.cocoapods文件夾
#注意xxx為本機用戶名
pod repo add /Users/xxx/.cocoapods/repos
  • 安裝rvm出現的坑報SSL_ERROR_SYSCALL in connection to raw.githubusercontent.com:443

通過以下IP 查詢工具查詢IP地址,然后我們需要在系統 hosts 文件中添加關聯的 ip 地址即可。具體請參考該鏈接
https://www.ipaddress.com/

最后編輯于
?著作權歸作者所有,轉載或內容合作請聯系作者
平臺聲明:文章內容(如有圖片或視頻亦包括在內)由作者上傳并發布,文章內容僅代表作者本人觀點,簡書系信息發布平臺,僅提供信息存儲服務。

推薦閱讀更多精彩內容