ng new
Lets create a new Angular application in the specific version using the ng new
command.
The Easy way to switch to a different version of Angular is uninstall the @angular/cli
and install the version we want for app.
Uninstall the Angluar CLI.
npm uninstall -g @angular/cli
Install Specific Version Angular CLI
Simply install the latest version.
npm install -g @angular/cli@6.1.1
Using npx for npm packages
- Use
npx
command which is Node.js package runner, by running packages directly from the registry without effecting the globally installed package registry-g
. - First, Need to install
npx
, and let’s do it globally.
npm install -g npx
When you need to create an angular project, just use this command,
npx -p @angular/cli@latest ng new projectName
Replace @latest
with your desired CLI version.
where
-p
– parameter where we put a specific@angular/cli version
.
npx -p @angular/cli@11.1.2 ng new MyNewApp
@next
will automatically install the latest preview version from Angular repo.
npx @angular/cli@next ng new myApp
DownGrade angular 8 to 7
npx -p @angular/cli@7.3.10 ng new MyApp7
The generated package.json
file has the following content
{ "name": "my-app7", "version": "0.0.0", "scripts": { "ng": "ng", "start": "ng serve", "build": "ng build", "test": "ng test", "lint": "ng lint", "e2e": "ng e2e" }, "private": true, "dependencies": { "@angular/animations": "~7.2.0", "@angular/common": "~7.2.0", "@angular/compiler": "~7.2.0", "@angular/core": "~7.2.0", "@angular/forms": "~7.2.0", "@angular/platform-browser": "~7.2.0", "@angular/platform-browser-dynamic": "~7.2.0", "@angular/router": "~7.2.0", "core-js": "^2.5.4", "rxjs": "~6.3.3", "tslib": "^1.9.0", "zone.js": "~0.8.26" }, "devDependencies": { "@angular-devkit/build-angular": "~0.13.0", "@angular/cli": "~7.3.10", "@angular/compiler-cli": "~7.2.0", "@angular/language-service": "~7.2.0", "@types/node": "~8.9.4", "@types/jasmine": "~2.8.8", "@types/jasminewd2": "~2.0.3", "codelyzer": "~4.5.0", "jasmine-core": "~2.99.1", "jasmine-spec-reporter": "~4.2.1", "karma": "~4.0.0", "karma-chrome-launcher": "~2.2.0", "karma-coverage-istanbul-reporter": "~2.0.1", "karma-jasmine": "~1.1.2", "karma-jasmine-html-reporter": "^0.2.2", "protractor": "~5.4.0", "ts-node": "~7.0.0", "tslint": "~5.11.0", "typescript": "~3.2.2" } }