2022 CocoaPods installation tutorial

2022 CocoaPods installation tutorial

Although the MacOS system comes with Ruby, it will not be upgraded if it is not managed.

Check rvm and install
  1. Check whether rvm is installed, execute the command in the terminal: rvm -v,
    If the terminal appears: rvm: command not found, it means rvm is not installed.
  2. Install rvm, use the command: curl -L get.rvm.io | bash -s stable, wait for the installation to complete
  3. After the installation is complete, follow the prompts and use the command: source ~/.rvm/scripts/rvm to start using rvm (you can not execute it, and it will not affect subsequent operations)
  4. Check whether the installation is successful, execute the command: rvm -v, and a statement similar to the following appears: rvm 1.29.9 (latest) by Michal Papis, Piotr Kuczynski, Wayne E. Seguin [https://rvm.io], That is, the installation is successful
Use rvm to install ruby ​​environment
  1. List all ruby ​​versions, execute the command: rvm list known
  2. Find # MRI Rubies. The following are all ruby ​​versions. The bottom one is the latest version. Here is [ruby-]3.0[.0]
  3. Install ruby ​​and execute the command: rvm install 3.0.0
  4. After the operation is completed, execute: rvm list to check the installed ruby ​​version
Check and update RubyGems (Ruby1.9.1 and later versions come with RubyGems)
  1. RubyGems is a convenient and powerful Ruby package manager. Ruby third-party plug-ins are managed using gems. It is very easy to publish and share. You can install third-party extension libraries with a simple command. The gem version needs to be 2.6.x to install CocoaPods without error.
  2. To check the gem version, execute: gem -v
  3. Update gem command: gem update --system
Check ruby ​​source and replace
  1. Check the source command: gem sources -l. If the source is https://rubygems.org/, it needs to be replaced.
  2. Remove sources:gem sources --remove https://rubygems.org/
  3. Add sources: gem sources --add https://gems.ruby-china.com
  4. To check the replacement result, execute: gem sources -l

The reason why we need to add the domestic ruby-china source is because the taobao source has stopped maintaining, so the ruby-china source is replaced here, and try to ensure that there is only one.

Install Cocoapods
  1. Execute: sudo gem install cocoapods (used under Xcode 10.11)
  2. Currently Xcode has been upgraded to 13 or above, you need to use: sudo gem install -n /usr/local/bin cocoapods
  3. If gems installed appears, it means the installation is successful.
Using Cocoapods
  1. Execute pod related instructions to check whether it is working properly. For example: pod search AFNetworking to view the results.
  2. cd Xcode project, execute: pod init
  3. Edit the podfile file and add the query results: pod 'AFNetworking', '~> 4.0.1'
  4. Execute: pod install, run the project
other
  1. Update the pod library, execute: pod repo update or pod install --repo-update
  2. Update CocoaPods:gem install cocoapods