I run into this issue because I had installed cocoapods using gems as indicated in the official website. However, with Macbookpros that have the M1 chip, that installation has some issues, you have to use brew to install cocoapods and rbenv to install ruby.
You can also use kdoctor to let you know if your environment is properly setup.
1- If you installed cocoapods using gem, then uninstall it sudo gem uninstall cocoapods
. If you install cocoapods manually, remove it manually. If not using ruby gem for anything else I would advise to unistall gem too.
2- Install homebrew if not installed.
3- Install rbenv using homebrew.
4- Install ruby 2.7.x using rbenv. Do not install ruby 3.x as of december 2022 it does not work properly with pod on M1 Macs.
5- Using rbenv switch to the version of ruby installed in step 4(2.7.x). You have to switch to a different ruby binary, different from the one that comes in Mac system. Cocoapods doesn't work well with the preinstalled one. Make sure which -a ruby
points to the one you installed using rbenv
6- Install cocoapods using brew brew install cocoapods
. Make sure which -a pod
points to the one you installed using brew
7- Run kdoctor, and run pod install again. You should be good to go.