The problem I had with this error was that my computer had outdated ruby, which was updated with a ruby version manager (rbenv) with the following command:
rbenv install 3.2.0 rbenv global 3.2.0
Once ruby was updated to the most recent version, my computer still had the problem and the problem was that it had an older version, this was because of the permissions that rbenv did not have and the PC continued using the old version, for this I applied the command
sudo chown -R $(whoami) ~/.rbenv
and reinstalled again
gem install ffi
gem install cocoapods
With this all the problems were solved.