Sivamohan Reddy
Sivamohan Reddy

Reputation: 574

how to work with different angular cli versions in the same machine

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

Answers (4)

Muhammad Ahmar Khan
Muhammad Ahmar Khan

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:

  • install nvm
  • look for node version that supports angular 4.x cli (my case: node 6.9.0) and install nvm install 6.9.0
  • install node version (my case: 12.14.0) for angular 12.x cli nvm install 12.14.0

Start setting up lower version first.

Angular 4.x setup:

  • switch to supported node version for angular 4.x nvm use 6.9.0
  • install Angular 4.x cli globally npm install -g @angular/[email protected]
  • create new angular project with angular 4.x or clone from repo, get into project directory
  • npm install if you have packages in package.json or install new packages
  • ng serve

Angular 12.x setup:

  • switch to supported node version for angular 12.x nvm use 12.14.0
  • uninstall global angular cli (4.x) npm uninstall -g @angular/cli
  • npm cache clean --force
  • install angular cli 12.x globally npm install -g @angular/[email protected]
  • create / get into existing angular 12.x project directory
  • npm install
  • ng serve

Switching between projects:

  • switch back to angular 4.x project (get into directory)
  • switch to respective node version nvm use 6.9.0
  • ng serve (it will use local cli version 4.x that is lower than the global 12.x)
  • same will do to switch to anular 12.x project with respective node version

Upvotes: 0

sanjay kumar
sanjay kumar

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

Rahul
Rahul

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

JB Nizet
JB Nizet

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

Related Questions