Reputation: 574
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.
Upvotes: 1
Views: 3362
Reputation: 339
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.0
nvm install 12.14.0
Start setting up lower version first.
Angular 4.x setup:
nvm use 6.9.0
npm install -g @angular/[email protected]
npm install
if you have packages in package.json or install new packagesng serve
Angular 12.x setup:
nvm use 12.14.0
npm uninstall -g @angular/cli
npm cache clean --force
npm install -g @angular/[email protected]
npm install
ng serve
Switching between projects:
nvm use 6.9.0
ng serve
(it will use local cli version 4.x that is lower than the global 12.x)Upvotes: 0
Reputation: 858
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.
Upvotes: 0
Reputation: 2128
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 !!
Upvotes: 0
Reputation: 691505
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.
Upvotes: 3