2 versions of xcodeproj exist and newer version is not being used by pod install

pod install throws error on Xcode 14/MacOS 12.5/M1/cocoapods 1.11.3:

RuntimeError - [Xcodeproj] Unknown object version (56).
/opt/homebrew/Cellar/cocoapods/1.11.3/libexec/gems/xcodeproj-1.21.0/lib/xcodeproj/project.rb:228:in `initialize_from_file'
/opt/homebrew/Cellar/cocoapods/1.11.3/libexec/gems/xcodeproj-1.21.0/lib/xcodeproj/project.rb:113:in `open'

Here the old version of xcodeproj 1.21.0 is being called. However gem list shows:

xcodeproj (1.22.0)

xcodeproj --version still returns 1.21.0 and which xcodeproj points to /opt/homebrew/bin/xcodeproj.

Here is the Podfile:

require_relative '../node_modules/react-native/scripts/react_native_pods'
require_relative '../node_modules/@react-native-community/cli-platform-ios/native_modules'

platform :ios, '13.0'
install! 'cocoapods', :deterministic_uuids => false

target 'xyz_app6' do
  config = use_native_modules!

  # Flags change depending on the env values.
  flags = get_default_flags()

  use_react_native!(
    :path => config[:reactNativePath],
    # to enable hermes on iOS, change `false` to `true` and then install pods
    :hermes_enabled => flags[:hermes_enabled],
    :fabric_enabled => flags[:fabric_enabled],
    # An absolute path to your application root.
    :app_path => "#{Pod::Config.instance.installation_root}/.."
  )

  target 'xyz_app6Tests' do
    inherit! :complete
    # Pods for testing
  end

  # Enables Flipper.
  #
  # Note that if you have use_frameworks! enabled, Flipper will not work and
  # you should disable the next line.
  #use_flipper!() #disabled by error in pod install

  post_install do |installer|
    react_native_post_install(installer)
    __apply_Xcode_12_5_M1_post_install_workaround(installer)
  end
end

Run gem cleanup xcodeproj multiple times without avail. How to make pod install using version xcodeproj 1.22.0 instead of old 1.21.0?

Here is gem uninstall Xcodeproj --version 1.21.0:

gem uninstall xcodeproj --version 1.21.0 Gem 'xcodeproj' is not installed

Just change objectVersion = 56 to objectVersion = 55 in project.pbxproj

uninstall cocoapods from brew: "brew uninstall cocoapods" and reinstall cocoapods with: "sudo gem install cocoapods". xcodeproj will be version 1.22.0

2 versions of xcodeproj exist and newer version is not being used by pod install
 
 
Q