Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to Create a specific version of Angular Project using CLI?

My npm version is 5.5.1 and angular cli version is 6.2.1. When I try to create a new project using the command ng new Project_name then it is creating the latest version of angular (in my case it is creating Angular version ^6.1.0). But I want Angular4. My question is how to create this Angualr2/4/5 (specific version instead of the latest version)? I don't think changing the version value in package.json will help in my case because there are some differences in the older versions and the latest 6 version (like the name of one file has been changed from angular-cli.json to anguar.json and not only name but content is also changed.) I've also raised the same question in Angular-cli Github site as well. click here

Thanks in advance!!

like image 595
Ravi Kumar B Avatar asked Sep 14 '18 12:09

Ravi Kumar B


People also ask

How do I run an older version of an Angular project?

There is a way to have the current version of Angular install the previous version use: npm install @angular/cli@<version> . Start with the current version of Angular installed (I have Angular 8 as of writing this article): vagrant@ubuntu-bionic:$ npm install @angular/cli ...

How do I switch between Angular versions?

You can try this out in your own application. Open your command line in the directory containing your application's package. json folder and execute npm run ng serve. You can also experiment by running ng -v then npm run ng -v which will run the version of your global and local Angular-CLIs.

How do I install specific version of Angular 10?

You can just have package. json with specific version and do npm install and it will install that version. Also you don't need to depend on angular-cli to develop your project.


2 Answers

Using CLI you can not create specific angular version.

But you can install specific version of angular CLI into particular folder.

For Example :

First create new folder inside any drive. I'm going to create demo folder in D drive. Ex: d:\projects\demo.

Then find this folder inside Command Prompt(cmd) or just type cmd into your created folder addressbar in windows and hit enter.

Now type angular specific version command : npm install @angular/[email protected] for angular 5. and use similar command for other version.

After complete the installation, just create new angular project into your specific folder that you recently install angular. Ex: d:\projects\demo\.

Now create angular project using the command ng new Project_name and it will create your specific angular version Project.

In my example it will create angular 5 project.

like image 74
Shashikant Devani Avatar answered Sep 17 '22 18:09

Shashikant Devani


You can use npx command which is Node.js package runner, by running packages directly from the registry without effecting the globally installed package registry (-g).

@next will automatically install the latest preview version from Angular repo (now days refers to version 9 rc), like so:

npx @angular/cli@next new Angular9Project 

Otherwise, you can provide the specific version:

npx @angular/cli@7 new Angular7Project 

NPX comes bundled with NPM version 5.2+

like image 24
EladTal Avatar answered Sep 19 '22 18:09

EladTal