1.执行命令:
bash
sudo gem install cocoapods
因为是新机,内置的ruby版本是(2.6.0)太低,会报错
所以需要安装新的ruby版本
2.如果已经安装了低版本的homebrew,可以先卸载:
卸载:
bash
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/uninstall.sh)"
安装最新版本:
bash
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
因为是外网所以需要设置VPN,或者修改电脑配置 hosts文件,添加:
bash
185.199.108.133 raw.githubusercontent.com
185.199.109.133 raw.githubusercontent.com
185.199.110.133 raw.githubusercontent.com
185.199.111.133 raw.githubusercontent.com
3.使用 homebrew 安装 最新版的ruby:
bash
brew install chruby ruby-install
安装结束会提示:
bash
- Run these two commands in your terminal to add Homebrew to your PATH:
(echo; echo 'eval "$(/opt/homebrew/bin/brew shellenv)"') >> /Users/guojunlong/.zprofile
eval "$(/opt/homebrew/bin/brew shellenv)"
- Run brew help to get started
- Further documentation:
https://docs.brew.sh
此时按照提示依次执行:
bash
(echo; echo 'eval "$(/opt/homebrew/bin/brew shellenv)"') >> /Users/guojunlong/.zprofile
eval "$(/opt/homebrew/bin/brew shellenv)"
然后安装 ruby3.2.2
bash
ruby-install ruby 3.2.2
4.配置环境:
bash
echo "source $(brew --prefix)/opt/chruby/share/chruby/chruby.sh" >> ~/.zshrc
echo "source $(brew --prefix)/opt/chruby/share/chruby/auto.sh" >> ~/.zshrc
echo "chruby ruby-3.2.2" >> ~/.zshrc
5.更新配置,并验证
bash
source ~/.zshrc
ruby -v
6.最后直接安装即可
bash
gem install cocoapods