1. Execute the command:
sudo gem install cocoapods
Because it is a new machine, the built-in ruby version (2.6.0) is too low, and an error will be reported
So a new ruby version needs to be installed
2. If you have already installed a lower version of homebrew, you can uninstall it first:
Uninstall:
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/uninstall.sh)"
Install the latest version:
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
Because it is an external network, you need to set up a VPN, or modify the computer configuration hosts file, add:
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. Use homebrew to install the latest version of ruby:
brew install chruby ruby-install
At the end of the installation, you will be prompted:
- 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
At this time, follow the prompts to execute in order:
(echo; echo 'eval "$(/opt/homebrew/bin/brew shellenv)"') >> /Users/guojunlong/.zprofile
eval "$(/opt/homebrew/bin/brew shellenv)"
Then install ruby3.2.2
ruby-install ruby 3.2.2
4. Configure the environment:
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. Update the configuration and verify
source ~/.zshrc
ruby -v
6. Finally, just install it directly
gem install cocoapods