1、Check the gem version:
2、If the gem version is less than 2.6.14, it is recommended to upgrade to version 2.6.14 or higher:
sudo gem update --system
3、Change the gem source:
sudo gem --remove https://rubygems.org
sudo gem --add http://gems.ruby-china.org
4、Use the Sudo-less install method to install CocoaPods:
a)、Create a new directory in your Home directory, such as Vendor/ruby
d)、gem install cocoapods -v 1.5
5、Add the environment variable from step 3b to the ~/.bash_profile file (if you have an Apple M1 chip, use the ~/.zshrc file) and execute:
Files related to CocoaPods that are installed using the above method will be installed in the Vendor/ruby directory under your home directory.
Execute the command pod –version in the terminal, if the result is 1.5, it means the installation was successful.