一、确保ruby环境存在,并且源是 https://gems.ruby-china.com
二、开始安装cocoapods
1.
sudo gem install -n /usr/local/bin cocoapods
2.
pod setup
3.
git clone https://github.com/CocoaPods/Specs.git ~/.cocoapods/repos/trunk
4.安装完成,测试一下
pod search AFNetworking
如果出现错误:/opt/homebrew/lib/ruby/gems/3.2.0/gems/activesupport-7.1.1/lib/active_support/core_ext/array/conversions.rb:108:in `<class:Array>': undefined method `deprecator' for ActiveSupport:Module (NoMethodError)
这是因为activesupport版本问题,需要后退下版本
1>. sudo gem install activesupport -v 7.0.8
2>.sudo gem uninstall activesupport
Select gem to uninstall:
1. activesupport-7.0.8
2. activesupport-7.1.1
3. All versions
选择2
再次测试pod --version,看到版本就成功了!
三、安装过程中出现意外
1. 如果执行 git clone git clone https://github.com/CocoaPods/Specs.git ~/.cocoapods/repos/trunk 特别慢,并且最后timeout,活着连接不到服务器等等错误导致没有执行成功的话,选择科学上网之后继续执行git clone git clone https://github.com/CocoaPods/Specs.git ~/.cocoapods/repos/trunk
2.如果安装完成之后,大部分的库已经可以用,比如bugly等一小部分库pod install失败的话,打开电脑网络设置->高级->DNS->+8.8.8.8;此时只要非特殊的库大部分都可以正常pod install了。
如果遇见podinstall执行特别慢,或者Failed to connect to github.com port 443: Operation timed out等问题可以修改hosts文件
1.查看github的IP地址
ping github.com
2.cmd+shift+G 快捷命令打开hosts文件所在的文件夹
/private/etc/hosts
3.把github的IP地址加入到hosts文件中
140.82.112.3 github.com
四、一些建议
建议不要出现问题了之后移除trunk,并且在podfile文件里添加source 'https://github.com/CocoaPods/Specs.git';这样去使用pod,因为trunk它pod install 的速度是挺快的,还有就是很有可能你这样操作了之后也是白忙活;