1、首先尝试命令更新pods
sudo gem install cocoapods
估计会报错:
ERROR: Error installing cocoapods:
The last version of securerandom (>= 0.3) to support your Ruby & RubyGems was 0.3.2. Try installing it with `gem install securerandom -v 0.3.2` and then running the current command again
securerandom requires Ruby version >= 3.1.0. The current ruby version is 2.7.2.137.
2、然后按照错误指引更新securerandom
sudo gem install -n /usr/local/bin securerandom -v 0.3.2
3、然后按照错误指引更新Ruby,先查看Ruby可安装列表
rvm list known
如果没有RVM,会报错找不到RVM指令,那么需要先安装RVM
curl -L get.rvm.io | bash -s stable
如果报错
[curl: (7) Failed to connect to raw.githubusercontent.com port 443: Connection refused]
解决办法:
(1)、打开网站: https://www.ipaddress.com/
查询一下 raw.githubusercontent.com 对应的IP 地址
选择一个IP 地址复制
(2)修改系统的host文件,通过命令行输入:
sudo vim /etc/hosts
按i进入编辑模式,在最底部粘贴
185.199.108.133 raw.githubusercontent.com
编辑完按esc退出,然后输入
:wq
回车,然后重启终端,再执行:
curl -L get.rvm.io | bash -s stable
然后就安装好RVM了,回到第三步
4、然后安装最新的Ruby(会等好久)
rvm install 3.1.0
5、然后安装pod
sudo gem install cocoapods
6、安装仓库
pod setup
7、拉去pod库
git clone https://mirrors.tuna.tsinghua.edu.cn/git/CocoaPods/Specs.git ~/.cocoapods/repos/trunk
到这里CocoaPods已经安装完成了
执行下面命令查看是否完成
pod search AFNetworking