1. Introduction
In this article, we are going to present a way to create a new Angular application in the specific version using the ng new
command. Sometimes when we have installed the latest version of @angular/cli
globally there is a need to build other applications in an older version of Angular.
2. Uninstall/Install @angular/cli
The simplest way to 'switch' to a different version of Angular is to uninstall the current @angular/cli
and install the version in which we want to create an application.
Let's say we have @angular/cli
in the latest version and we want to downgrade it to version 8.
First, we need to uninstall the latest version, then simply install the version we are interested in:
After it is installed, we can run:
This will create an Angular 8 project with the correct dependencies.
3. Using npx
for executing npm package binaries
The other method to create Angular application in a specific version is to use npx command that executes npm package binaries.
First, we need to install npx, and let's do it globally:
Then we just need to execute npx
command with the -p
parameter where we put a specific @angular/cli
version. The last element of this statement is a command that creates an application on a specific @angular/cli
version ng new [name of the project]
.
For example, when we want to create an Angular application in version 8 we just need to run the following command:
The generated package.json
file has the following content:
As you can see all application dependencies are in version 8:
4. Conclusion
Probably every web developer faced this problem once in their career: "How to use ng new app
and have an Angular 5 app? Or Angular 4?. In this article, we presented two ways to generate Angular applications in a particular version. We prefer using the npx
command because it is simple.
{{ 'Comments (%count%)' | trans {count:count} }}
{{ 'Comments are closed.' | trans }}