前言
CocoaPods 安装有什么麻烦的?直接上官网 https://cocoapods.org/ 照着安装不就行了。
如果你这么想,那就大错特错了。今天我们就盘一下 CocoaPods 安装的那些坑。
开始
替换源
自带的源太慢了,我换了好几个梯子都不行,所以强烈建议大家还是替换成国内的源:
# 移除默认源,添加国内源
gem sources --add https://gems.ruby-china.com/ --remove https://rubygems.org/
# 确认是否移除成功
gem sources -l
# 没问题,看来是成功了!
*** CURRENT SOURCES ***
https://gems.ruby-china.com/ruby版本太老:
# 执行这句开始安装
sudo gem install cocoapods -V
# 报错 1 :ruby 版本太老,运行以下任务
ERROR: Error installing cocoapods:
The last version of activesupport (>= 5.0, < 8) to support your Ruby & RubyGems was 6.1.7.10. Try installing it with `gem install securerandom -v 0.3.2` and then running the current command again
activesupport requires Ruby version >= 3.1.0. The current ruby version is 2.6.10.210.
sudo gem install securerandom -v 0.3.2
# 报错 2 :ruby 版本太老,运行以下任务
ERROR: Error installing cocoapods:
The last version of activesupport (>= 5.0, < 8) to support your Ruby & RubyGems was 6.1.7.10. Try installing it with `gem install drb -v 2.0.6` and then running the current command again
activesupport requires Ruby version >= 3.1.0. The current ruby version is 2.6.10.210.
sudo gem install drb -v 2.0.6
# 报错 3 :ruby 版本太老,运行以下任务
ERROR: Error installing cocoapods:
The last version of activesupport (>= 5.0, < 8) to support your Ruby & RubyGems was 6.1.7.10. Try installing it with `gem install activesupport -v 6.1.7.10` and then running the current command again
activesupport requires Ruby version >= 3.1.0. The current ruby version is 2.6.10.210.
sudo gem install activesupport -v 6.1.7.10
# 报错 4 : ruby 太老
ERROR: Error installing activesupport:
The last version of zeitwerk (~> 2.3) to support your Ruby & RubyGems was 2.6.18. Try installing it with `gem install zeitwerk -v 2.6.18` and then running the current command again
zeitwerk requires Ruby version >= 3.2. The current ruby version is 2.6.10.210.不停往下还是报错,根本原因 ruby 太老,我们安装 rvm 解决。
rvm 使用
rvm 地址: https://rvm.io/
先安装gpg2 : brew install gpg2
成功后安装证书(注意,不要开梯子!不要开梯子!可以连手机热点):
gpg --keyserver keyserver.ubuntu.com --recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3 7D2BAF1CF37B13E2069D6956105BD0E739499BDB
gpg: 密钥 105BD0E739499BDB: 1 个重复签名被移除
gpg: /Users/mac/.gnupg/trustdb.gpg:建立了信任度数据库
gpg: 密钥 105BD0E739499BDB:公钥 “Piotr Kuczynski <piotr.kuczynski@gmail.com>” 已导入
gpg: 密钥 3804BB82D39DC0E3:公钥 “Michal Papis (RVM signing) <mpapis@gmail.com>” 已导入
gpg: 处理的总数:2
gpg: 已导入:2最后,安装 rvm:
curl -sSL https://get.rvm.io | bash -s stable