Cocoapods安裝方法-最新版2020.6.10

1.查看當(dāng)前Ruby版本

ruby -v

2.升級(jí)Ruby環(huán)境,首先需要安裝RVM

curl -L get.rvm.io | bash -s stable
source ~/.bashrc 
source ~/.bash_profile

3.查看rvm版本

rvm -v

顯示如下:

rvm 1.29.3 (latest) by Michal Papis, Piotr Kuczynski, Wayne E. Seguin [https://rvm.io]

4.列出Ruby可安裝的版本信息

rvm list known

顯示如下:

# 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[.7] [ruby-]2.4[.4] [ruby-]2.5[.1] ..... [ruby-]2.6[.3] // 重點(diǎn)在這里 重點(diǎn)在這里 重點(diǎn)在這里 [ruby-]2.7[.0-preview1] // 測(cè)試版 ruby-head .....

5.安裝一個(gè)Ruby版本

rvm install 2.6.3 

// 注意:安裝過程中需要兩次按下 Enter 鍵, 第二次按下后需要輸入電腦訪問密碼(不可見,只管輸入就行); // 如果你電腦沒有安裝Xcode和Command Line Tools for Xcode以及Homebrew 會(huì)自動(dòng)下載安裝,建議提前安裝這三者.

這里很多小伙伴會(huì)遇到錯(cuò)誤,大部分是因?yàn)闆]有安裝Homebrew造成,所以所以所以要提前安裝比較好

/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

6.設(shè)置為默認(rèn)版本

rvm use 2.6.3 --default

7.更換源

sudo gem update --system 
gem sources --remove https://rubygems.org/ 
gem sources --add  https://gems.ruby-china.com/

8.驗(yàn)證Ruby鏡像

gem sources -l

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

9.正式開始安裝Cocoapods

sudo gem install -n /usr/local/bin cocoapods

10.如果安裝多個(gè)Xcode使用下面的命令選擇

sudo xcode-select  -switch  /Applications/Xcode.app/Contents/Developer

11.安裝本地庫(kù)

pod setup

12.重點(diǎn)

最新版的MacOS Catalina系統(tǒng)命令行執(zhí)行pod setup命令直接結(jié)束啦;

莫著急,我們手動(dòng)安裝本地庫(kù),速度絕對(duì)快

命令行執(zhí)行以下操作

git clone https://github.com/CocoaPods/Specs.git ~/.cocoapods/repos/trunk

注意: 注意: 注意: 重要的事情要重申: 使用這個(gè)命令執(zhí)行等待一段時(shí)間之后大有可能會(huì)失敗, 原因基本是網(wǎng)絡(luò)問題, 請(qǐng)不要著急, 根據(jù)自己和小伙伴的多次測(cè)試, 只有在使用移動(dòng)手機(jī)網(wǎng)絡(luò)或者在凌晨的時(shí)候網(wǎng)速才會(huì)理想 (大概幾分鐘就OK,其他情況下即使你的網(wǎng)絡(luò)帶寬很好也沒用)

或者使用下面的,國(guó)內(nèi)鏡像,速度剛剛的

git clone https://mirrors.tuna.tsinghua.edu.cn/git/CocoaPods/Specs.git ~/.cocoapods/repos/trunk

如果還不行

// 安裝最新版
cocoapods sudo gem install cocoapods --pre
// 移除本地
master sudo rm -fr ~/.cocoapods/repos/master 
// 移除本地緩存
 sudo rm -fr ~/Library/Caches/CocoaPods/  
// 重新setup,如果很慢可使用問題1的解決方法(git clone) 
pod setup --verbose 
// 移除trunk 
pod repo remove trunk

13.下載安裝完成檢查

pod search AFNetworking

14.Cocoapods的具體使用

創(chuàng)建Podfile文件

pod init

打開Podfile文件

open Podfile

添加庫(kù)

pod 'AFNetworking'

下載

pod install
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

友情鏈接更多精彩內(nèi)容