Run the following command to to install the latest version of the Capacitor CLI to your project:
npm i -D @capacitor/cli@latest
After that, run the following command to execute the capacitor migrate command:
npx cap migrate
You will get a prompt like this:
Please note this tool is not intended for use in a mono-repo enviroment, please check out the Ionic vscode extension for this functionality. [?] Capacitor 4 sets a deployment target of iOS 13 and Android 12 (SDK 32). ✔ Are you sure you want to migrate? (Y/n) … y [?] Would you like the migrator to run npm install to install the latest versions of capacitor packages? (Those using other package managers should answer N) ✔ Run Npm Install? (Y/n) … y
Please select the default actions presented by the terminal, when the installation is done you will be presented with the following message:
[success] Migration to Capacitor ^4.0.0 is complete. Run and test your app!
Run the npm i command after that to install all the latest packages..
You are done with installation the latest capacitor version in your project.