1.安装顺序
Homebrew --> rvm --> ruby --> cocoa-pods
2. 安装Homebrew
2.1 查看安装的版本信息
brew --version
终端查询结果
Homebrew 3.6.21
Homebrew/homebrew-core (git revision 1d02c20b2a2; last commit 2023-02-08)
Homebrew/homebrew-cask (git revision cd3977d330; last commit 2023-02-08)
2.2 官方提供的安装方法
/bin/bash -c "$(curl -fsSL [https://raw.githubusercontent.com/Homebrew/install/master/install.sh](https://raw.githubusercontent.com/Homebrew/install/master/install.sh))"
出现如下错误,需要进入系统hosts文件配置域名ip解析。
curl: (7) Failed to connect to [raw.githubusercontent.com](http://raw.githubusercontent.com/) port 443: Connection refused
解决方案
步骤1. 获取raw.githubusercontent.com IP地址, 输入raw.githubusercontent.com查询
步骤2. /etc -> hosts
步骤3. 配置
##
# Host Database
#
# localhost is used to configure the loopback interface
# when the system is booting. Do not change this entry.
##
127.0.0.1 localhost
255.255.255.255 broadcast host
185.199.108.133 [raw.githubusercontent.com](http://raw.githubusercontent.com/)
185.199.109.133 [raw.githubusercontent.com](http://raw.githubusercontent.com/)
185.199.110.133 [raw.githubusercontent.com](http://raw.githubusercontent.com/)
185.199.111.133 [raw.githubusercontent.com](http://raw.githubusercontent.com/)
::1 localhost
2.3使用国内源进行安装
/bin/zsh -c "$(curl -fsSL [https://gitee.com/cunkai/HomebrewCN/raw/master/Homebrew.sh](https://gitee.com/cunkai/HomebrewCN/raw/master/Homebrew.sh))"
安装完后执行
source /Users/apple/.rvm/scripts/rvm
3. 安装rvm
3.1 检查rvm是否安装
rvm -v
终端结果,出现如下则说明安装过
rvm 1.29.12 (latest) by Michal Papis, Piotr Kuczynski, Wayne E. Seguin [[https://rvm.io](https://rvm.io/)]
3.2 更新rvm
rvm get stable
若执行失败,可以在命令前加入sudo权限
sudo rvm get stable
3.3 安装rvm,下面命令都需要执行
安装rvm
curl -L [https://get.rvm.io](https://get.rvm.io/) | bash -s stable
载入rvm
source ~/.rvm/scripts/rvm
4. 安装ruby
4.1 在终端中查看ruby的版本信息
ruby -v
结果如下,当ruby版本低于2.2.2时,安装cocoapods会报错
ruby 2.7.2p137 (2020-10-01 revision 5445e04352) [x86_64-darwin21]
4.2 查看ruby在系统中可安装的版本信息
rvm list known
4.3 安装ruby,建议安装最新版本
rvm install 3.0.0
4.4 查看是否安装成功
ruby -v
4.5 将ruby该版本设置默认使用
rvm use 3.0.0 --default
4.6 更换国内源
第一步移除旧源
gem sources --remove [https://rubygems.org/](https://rubygems.org/)
添加china源
gem sources --add [https://gems.ruby-china.com/](https://gems.ruby-china.com/)
检查源
gem sources -l
5. 安装cocoaPods
sudo gem install -n /usr/local/bin cocoapods
sudo gem install cocoapods
pod setup