Is there a way to specify angular version with the ng new command

There is no way to tell Angular CLI the specific Angular version you want to install. Instead, you can switch to another version of the Angular CLI and then create Angular project.

Run these commands first:

npm uninstall -g @angular/cli
npm install -g @angular/[email protected]

After it is installed, you can run:

ng new angular7

This will create your Angular 7 project with correct dependencies:

"@angular/animations": "~7.1.0",
"@angular/common": "~7.1.0",
"@angular/compiler": "~7.1.0",
"@angular/core": "~7.1.0",
"@angular/forms": "~7.1.0"

It can be done by using npx command that downloads and runs the package without installing it.

For example, npx @angular/cli@9 new my-project creates a new folder my-project in the current folder and puts a new project here using angular version 9. The local version of @angular/cli in this case will be the same as used in npx command so you can just continue working.

The syntax of the command is as follows npx @angular/cli@<package version> new <project-name>.


You can also install the angular CLI locally... lets say in /my-folder:

Run inside my-folder: npm i @angular/cli

This installs the latest available version of the CLI, but you can install whatever existing version (e.g. npm i @angular/[email protected])

When the npm install is done the angular CLI will land here: /my-folder/node_modules/@angular/cli

Inside my-folder you can run ng new my-project

This will create a new angular project here: /my-folder/my-project

The angular version of the new project will match the local CLI version.

Finally you should remove /my-folder/node_modules It is not needed anymore.

The ng commands will use by default the local angular CLI (in this case inside /my-folder/node_modules). If there is no local CLI then the global CLI will be used.