目录
- 快速检测Mac中各个环境
- 前言
- 【一】安装RVM
- 【二】安装Homebrew
- 【三】安装Ruby环境
- 【四】切换Source源,替换Ruby源
- 【五】升级Gem
- 【六】安装Cocoapods
- 补充:MacOS默认会安装好
ruby
环境,如果ruby
环境已经安装好,则直接跳过进行第四步骤。
-
快速检测MacOS中各个环境:
检测RVM:
rvm -v
检测Homebrew:brew --version
检测Ruby:ruby -v
检测Sources源:gem sources -l
检测Gem版本:gem -v
检测Cocoapods版本:pod --version
前言
我这台设备是M1芯片的Macmini,最近清空系统了,需要重新配置一下CocoaPods,并做个记录。
2020款M1 Mac mini
macOS Monterry 12.2.1
Xcode版本:Version 13.3
【一】安装RVM
-
打开终端,执行以下命令:
curl -L get.rvm.io | bash -s stable
结果输出:
mac@Macmini ~ % curl -L get.rvm.io | bash -s stable
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 194 100 194 0 0 375 0 --:--:-- --:--:-- --:--:-- 380
100 24535 100 24535 0 0 15449 0 0:00:01 0:00:01 --:--:-- 89871
Downloading https://github.com/rvm/rvm/archive/1.29.12.tar.gz
curl: (28) Operation timed out after 30005 milliseconds with 0 out of 0 bytes received
curl: (28) Connection timed out after 30005 milliseconds
Downloading https://github.com/rvm/rvm/releases/download/1.29.12/1.29.12.tar.gz.asc
curl: (28) Connection timed out after 30005 milliseconds
curl: (28) Connection timed out after 30005 milliseconds
curl: (28) Connection timed out after 30005 milliseconds
Found PGP signature at: 'https://github.com/rvm/rvm/releases/download/1.29.12/1.29.12.tar.gz.asc',
but no GPG software exists to validate it, skipping.
Upgrading the RVM installation in /Users/mac/.rvm/
RVM PATH line found in /Users/mac/.mkshrc /Users/mac/.profile /Users/mac/.bashrc /Users/mac/.zshrc.
RVM sourcing line found in /Users/mac/.profile /Users/mac/.bash_profile /Users/mac/.zlogin.
Upgrade of RVM in /Users/mac/.rvm/ is complete.
Thanks for installing RVM
Please consider donating to our open collective to help us maintain RVM.
Donate: https://opencollective.com/rvm/donate
-
查看rvm是否安装成功
rvm -v
结果输出:
mac@Macmini ~ % rvm -v
rvm 1.29.12 (latest) by Michal Papis, Piotr Kuczynski, Wayne E. Seguin [https://rvm.io]
【二】安装Homebrew
ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
如果出现如下错误提示
zsh: command not found: brew
则切换方案【一】
/bin/zsh -c "$(curl -fsSL https://gitee.com/cunkai/HomebrewCN/raw/master/Homebrew.sh)"
我这里选择中科大的源序号1,需要输入开机密码,接来来验证是否安装成功:
brew --version
mac@Macmini ~ % brew --version
Homebrew 3.4.2-19-g600d84e
Homebrew/homebrew-core (git revision 32611b17187; last commit 2022-03-21)
Homebrew/homebrew-cask (git revision 616d8706df; last commit 2022-03-21)
【三】安装Ruby环境
列出已有的ruby
rvm list known
mac@Macmini ~ % 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[.8]
[ruby-]2.4[.10]
[ruby-]2.5[.8]
[ruby-]2.6[.6]
[ruby-]2.7[.2]
[ruby-]3[.0.0]
ruby-head
# Ruby Enterprise Edition
ree-1.8.6
ree[-1.8.7][-2012.02]
# IronRuby
ironruby[-1.1.3]
ironruby-head
我这里安装最新版本
brew rvm install 3.0.0
安装成功后,我们让其在本地环境中生效:
rbenv shell 3.0.0
查询已经安装的ruby
rvm list
Ruby 设置为系统默认版本
rvm 3.0.0 --default
查看是否设置正确
ruby -v
mac@Macmini ~ % ruby -v
ruby 2.6.8p205 (2021-07-07 revision 67951) [universal.arm64e-darwin21]
【四】切换Source源,替换Ruby源
因为Ruby的默认源使用的是cocoapods.org,国内访问这个网址有时候会有问题,通常解决方案是将远替换成国内Ruby镜像
//删除原始的源
gem sources --remove https://rubygems.org/
//添加新源(国内Ruby镜像)
gem source -a https://gems.ruby-china.com
验证是否替换成功
gem sources -l
输出如下结果表示替换成功:
*** CURRENT SOURCES ***
https://gems.ruby-china.com
【五】升级Gem
Gem
是来管理Ruby
标准包,升级Gem
:
sudo gem update --system
查看当前gem
版本
gem -v
mac@Macmini ~ % gem -v
3.0.3.1
不升级在下面步骤可能会报很多错误的,因为Gem版本太低,无法安装CocoaPods。
【六】安装Cocoapods
sudo gem install -n /usr/local/bin cocoapods
查看是否安装成功
pod --version
mac@Macmini ~ % pod --version
1.11.2
安装成功执行
pod setup
将Github上的开源库都托管都安装Podspec索引安装到到本地
检测是否安装成功:可以利用搜索AFNetworking来检测是否能搜索到
pod search AFNetworking
mac@Macmini ~ % pod search AFNetworking
Setup completed
Creating search index for spec repo 'master'..
第一次会出现上面的 Creating search index for spec repo 'master'..
等到 出现 Done
后 就会出现我们搜索的结果,再次输入命令就不会出现这行代码了,直接就能搜索了。
如果出现以下报错等
[!] CDN: trunk - Cannot perform full-text search because Algolia returned an error: 0: Cannot reach any host: execution expired, execution expired, execution expired, execution expired
可以用终端执行命令 pod repo remove trunk
,然后重启终端即可。
-> AFNetworking (4.0.1)
A delightful networking framework for Apple platforms.
pod 'AFNetworking', '~> 4.0.1'
- Homepage: https://github.com/AFNetworking/AFNetworking
- Source: https://github.com/AFNetworking/AFNetworking.git
- Versions: 4.0.1, 4.0.0, 3.2.1, 3.2.0, 3.1.0, 3.0.4, 3.0.3, 3.0.2, 3.0.1, 3.0.0, 3.0.0-beta.3, 3.0.0-beta.2,
3.0.0-beta.1, 2.7.0, 2.6.3, 2.6.2, 2.6.1, 2.6.0, 2.5.4, 2.5.3, 2.5.2, 2.5.1, 2.5.0, 2.4.1, 2.4.0, 2.3.1, 2.3.0,
2.2.4, 2.2.3, 2.2.2, 2.2.1, 2.2.0, 2.1.0, 2.0.3, 2.0.2, 2.0.1, 2.0.0, 2.0.0-RC3, 2.0.0-RC2, 2.0.0-RC1, 1.3.4, 1.3.3,
1.3.2, 1.3.1, 1.3.0, 1.2.1, 1.2.0, 1.1.0, 1.0.1, 1.0, 1.0RC3, 1.0RC2, 1.0RC1, 0.10.1, 0.10.0, 0.9.2, 0.9.1, 0.9.0,
0.7.0, 0.5.1 [master repo]
- Subspecs:
- AFNetworking/Serialization (4.0.1)
- AFNetworking/Security (4.0.1)
- AFNetworking/Reachability (4.0.1)
- AFNetworking/NSURLSession (4.0.1)
- AFNetworking/UIKit (4.0.1)
-> AFNetworking+AutoRetry (0.0.5)
Auto Retries for AFNetworking requests
pod 'AFNetworking+AutoRetry', '~> 0.0.5'
- Homepage: https://github.com/shaioz/AFNetworking-AutoRetry
- Source: https://github.com/shaioz/AFNetworking-AutoRetry.git
- Versions: 0.0.5, 0.0.4, 0.0.3, 0.0.2, 0.0.1 [master repo]
到此就代表 CocoaPods 真正安装成功!