在安裝cocoapods上經歷過不少折騰,終於實現了較爲流暢的安裝過程,在此做個記錄,以便不時之需。
首先打開終端
1.安裝Homebrew
/bin/zsh -c "$(curl -fsSL https://gitee.com/cunkai/HomebrewCN/raw/master/Homebrew.sh)"
2.安裝rvm
curl -L get.rvm.io | bash -s stable
source ~/.bashrc
source ~/.bash_profile
報錯:curl: (7) Failed to connect to raw.githubusercontent.com port 443: Connectio
詢真實IP 通過IPAddress.com首頁,輸入raw.githubusercontent.com
查詢到真實IP地址
2.1 修改hosts
sudo vi /etc/hosts
打開hosts
i
插入
esc
退出
: wq
保存
3.更新系統上的ruby
rvm install 2.6.3
這裏我直接安裝的是2.6.3版本,如果你想安裝其他版本,也可先使用
rvm list known
列出可安裝的版本,然後用install命令安裝
4.將剛剛安裝的ruby設置爲默認版本
rvm use 2.6.3 --default
5.更換ruby鏡像源
sudo gem update --system
gem sources --remove https://rubygems.org/
gem sources --add https://gems.ruby-china.com/
可以使用
gem sources -l
來看是否更換成功
6.安裝CocoaPods
sudo gem install -n /usr/local/bin cocoapods
7.clone CocoaPods倉庫
這裏使用的是清華大學fork的CocoaPods倉庫
git clone https://mirrors.tuna.tsinghua.edu.cn/git/CocoaPods/Specs.git ~/.cocoapods/repos/trunk
也可以用gitee上的私人倉庫,這個是我自己的,如果更新過慢可以看我這個 [Cocoapods] - 更新 Cocoapods 庫如何解決 pod setup 過慢的問題
https://gitee.com/satoshi_uma/master
上面兩個CocoaPods倉庫選擇一個clone就行了
到這裏CocoaPods已經安裝完成了,可以使用
pod search AFNetworking
來檢查是否能正常使用
*如果你是M1芯片的Mac,還需要做以下操作:
1.訪達-應用程序-實用工具裏,右鍵點擊終端-顯示簡介 (如果找不到實用工具,請以列表或分欄的方式顯示項目)
2.勾選使用Rosetta打開
3.執行sudo gem install ffi
附:
1.Homebrew官方鏡像地址
/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
2.CocoaPods官方repo地址
git clone https://github.com/CocoaPods/Specs.git ~/.cocoapods/repos/trunk