I'm working with two projects one project is using Angular2 Cli and another one needs to use Angular6.
How can I install both versions of CLI and based on the project needs to switch Angular CLI versions
Is there any way to do that.
Each project has its own version of the CLI installed in its own node_modules directory.
The globally installed CLI just delegates to the project-specific CLI. I.e. if you're in the project1, the global cli delegates to the CLI installed in project1/node_modules, and if you're in project2, it delegates to the CLI installed in project2/node_modules.
So you have nothing special to do. It's already taken care of.
Just by adding your version in package.json is fine - when you run npm install mentioned version will get updated and installed
If you try to upgrade or downgrade your cli version it might cause issue on existing project - just intall correct CLI version when you create the project - hope this helps
Thanks - happy coding !!
If you have single account in your machine and installed Angular6 after than Angular2 then both project work because both have own node_modules folder and packages.json file but when you run Angular2 project then it will display warning for upgrade the version.
You should need to create second account in your machine and install the Angular6 under this account then it will work without warning.
100% working solution / hack:
Note: This solution is for existing projects since in most of the cases older version projects already exist.
I'd like to share my case that has angular 4.x and 12.x cli projects pulled from Git repo.
Install nvm and Node versions:
nvm install 6.9.0nvm install 12.14.0Start setting up lower version first.
Angular 4.x setup:
nvm use 6.9.0npm install -g @angular/[email protected]npm install if you have packages in package.json or install new packagesng serveAngular 12.x setup:
nvm use 12.14.0npm uninstall -g @angular/clinpm cache clean --forcenpm install -g @angular/[email protected]npm installng serveSwitching between projects:
nvm use 6.9.0ng serve (it will use local cli version 4.x that is lower than the global 12.x)