You don't have to only install the version tha it's compatible with your Angular version, but you have to also update your project.
To do so, you use the ng update command. It updates the entire project and its dependencies to align with the latest version of Angular. It updates the Angular packages and modifies the project's configuration files and codes to align with the latest version of Angular.
You can refer to these links. They are really helpful: