How to Run Multiple Angular Projects with Multiple versions

Running multiple Angular projects on a single machine with different versions of Angular can be tricky. The task also becomes more challenging because Angular depends on Node.js. Various versions of Angular require different versions of Node.js to run. In this tutorial, we’ll walk you through how to set up and run multiple Angular projects with different Angular and Node.js versions on the same machine.

Multiple Angular versions

Angular projects depend on Node.js, TypeScript, and RxJS. While you can install TypeScript and RxJS locally for each project without issue, compatibility problems arise when you want to run older Angular versions, alongside the newer versions. This is because each version of Angular requires specific Node.js versions.

To help you manage multiple Angular versions on a single machine, you can use the following tools:

  • NVM (Node Version Manager): To manage and switch between different versions of Node.js.
  • NPX: To execute different versions of Angular CLI without globally installing them.

Refer to the article, Angular version history to see the compatibility matrix for Angular, Node.js, TypeScript, and RxJS versions.

What is NPX?

NPX stands for Node Package eXecute, and it works similarly to NPM. NPX allows us to execute npm packages directly, even if we have not installed them locally. If the required package is not found locally, NPX will download it from the npm registry and execute it for us.

NPX is included with Node.js (version 8.0 or higher) or npm (version 5.2.0 or higher) and is installed automatically. If, for any reason, NPX is not installed on your system, you can install it using the following command.

You can verify the installed version of NPX with

You can now use NPX to create Angular projects and execute Angular CLI commands with the desired version of Angular. To create a new Angular project with the latest version of Angular CLI.

To create a new project with a specific version (e.g., Angular 11 / Angular 18)

You can also generate components within a project.

Use it to serve the project.

You can also build the project.

Running Multiple versions of Node using nvm

NVM (Node Version Manager) is a command-line tool that helps you install and manage multiple versions of Node.js. This allows you to switch between different versions depending on the project you’re working on.

Installing NVM on Linux

To install NVM on Linux, you can use one of the following commands

with curl

with wget

Installing NVM on Windows

For Windows users, you can download the NVM installer from the NVM Releases page and run the nvm-setup.exe file.

Before installing NVM on Windows, you should uninstall any existing global installation of Node.js. We will reinstall Node.js using NVM.

Installing different versions of Node.js 

To install the latest version of Node.js:

To install the latest LTS (Long Term Support) version

Install a specific version of Node.js (e.g., version 17.2.0)

To see all the installed versions of Node.js

Switch Between Node.js versions

To switch between installed versions of Node.js, use

Use nvm alias for Easier Switching. The code below creates an alias angular11 for Node.js version 12.11.1

Now. you can use the alias name instead of Node.js version

Similarly, you can create aliases.

Creating Angular 11 Project using npx & nvm

Let’s create an Angular project with a specific version of Node.js and Angular CLI.

Install Node 12.11.1 using nvm

Installing node using nvm

Switch to the installed version of Node.js:

Selecting the node version using nvm

Use NPX to create a new Angular 11 project:

Create a new angular project using npx

Navigate to your project directory and serve the project:

You can also use NPX to run other Angular commands, such as building the project

Similarly, you can create an Angular 18 project

You can find out the installed Angular CLI, Node.js, TypeScript, and RxJS versions.

References

Summary

By using NVM and NPX, you can easily switch between different versions of Node.js and Angular, enabling you to work on multiple Angular projects with different version requirements on the same machine.

Leave a Comment

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Scroll to Top