If you have a old ruby version (probably macOS built in), perhaps, you won't update gem or install cocoapods successfully.
May be like this:
YAML safe loading is not available. Please upgrade psych to a version that supports safe loading.
So, if you got problem like this
Here is the solution:
⚠️homebrew should be installed
brew install ruby
brew link --overwrite ruby
sudo gem update --system
sudo gem install cocoapods
You can copy each line and run from terminal.
BTW:
If you have a newer version of ruby, just run these to install cocoapods
sudo gem update --system
sudo gem install cocoapods