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
- 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. - Install rvm, use the command:
curl -L get.rvm.io | bash -s stable
, wait for the installation to complete - 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) - 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
- List all ruby versions, execute the command:
rvm list known
- Find
# MRI Rubies
. The following are all ruby versions. The bottom one is the latest version. Here is[ruby-]3.0[.0]
- Install ruby and execute the command:
rvm install 3.0.0
- 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)
- 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.
- To check the gem version, execute:
gem -v
- Update gem command:
gem update --system
Check ruby source and replace
- Check the source command:
gem sources -l
. If the source ishttps://rubygems.org/
, it needs to be replaced. - Remove sources:
gem sources --remove https://rubygems.org/
- Add sources:
gem sources --add https://gems.ruby-china.com
- 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
- Execute:
sudo gem install cocoapods
(used under Xcode 10.11) - Currently Xcode has been upgraded to 13 or above, you need to use:
sudo gem install -n /usr/local/bin cocoapods
- If
gems installed
appears, it means the installation is successful.
Using Cocoapods
- Execute pod related instructions to check whether it is working properly. For example:
pod search AFNetworking
to view the results. - cd Xcode project, execute:
pod init
- Edit the
podfile
file and add the query results:pod 'AFNetworking', '~> 4.0.1'
- Execute:
pod install
, run the project
other
- Update the pod library, execute:
pod repo update
orpod install --repo-update
- Update CocoaPods:
gem install cocoapods