As a developer, you might encounter projects requiring different Angular versions, especially if you work on legacy systems or contribute to multiple projects. Managing various Angular versions on the same machine might seem daunting, but with the right tools and approach, it’s completely achievable. This guide walks you through setting up multiple Angular versions on a Windows machine to ensure a smooth development experience.
The following step-by-step guide ensures that you can work seamlessly across Angular versions without conflicts.
To manage different Node.js versions (and indirectly Angular CLI versions), install Node Version Manager (NVM) for Windows:
C:\nvm
).C:\Program Files\nodejs
).nvm --version
To keep Angular versions isolated:
C:\AngularProjects
.C:\AngularProjects\Angular9
C:\AngularProjects\Angular12
C:\AngularProjects\Angular18
This organization ensures that each Angular version has its own workspace.
Global Angular CLI installations can lead to version conflicts. Instead, install Angular CLI locally within each project folder.
C:\AngularProjects\Angular9
.Install the desired Angular CLI version locally:
npm install @angular/cli@<version>
Replace <version>
with the desired Angular CLI version, e.g., @angular/cli@9
.
For Angular 9: Run in C:\AngularProjects\Angular9
:
npx @angular/cli@9 new my-angular9-app
Different Angular versions are compatible with specific Node.js versions. Refer to the Angular Documentation to identify the appropriate Node.js version for each Angular version.
Use NVM to install the required Node.js versions:
nvm install <version>
Replace <version>
with the compatible Node.js version, e.g., nvm install 14.17.0
.
Verify the installation:
nvm list
To work on a specific Angular version:
C:\AngularProjects\Angular9
.Switch to the compatible Node.js version:
nvm use <version>
For example:
nvm use 14.17.0
Install Angular CLI (if not already installed) locally:
npm install @angular/cli@<version>
Whenever you switch between Angular projects, ensure you switch the Node.js version accordingly:
nvm use <version>
command for the project you want to work on.Test your environment by:
Running the Angular development server in a specific project folder:
ng serve
Verifying that the correct Angular CLI and Node.js versions are in use:
ng version
node -v
npx
to run Angular CLI commands without installing them permanently.By following these steps, you'll be able to manage multiple Angular versions effectively, making your development workflow more flexible and efficient.