Sajad
Sajad

Reputation: 3807

How to install a specific version of Angular with Angular CLI?

I searched through google and angular cli doc but couldn't find any way to install a specific version of Angular using Angular CLI. is it even possible?

Upvotes: 194

Views: 780880

Answers (27)

Shishir
Shishir

Reputation: 326

  1. npm uninstall -g @angular/cli
  2. npm cache clean
  3. npm install -g @angular/cli@18
  4. npm install --save-dev @angular/cli@18
  5. To verify: ng version enter image description here

Upvotes: 1

Dax
Dax

Reputation: 1414

Basically, IF you need to create-app with 16.2.0 version

  • and you installed latest one by : ( npm install -g @angular/cli )
  • For example - Currently, it has 17

then you need to remove current CLI version by

npm uninstall -g @angular/cli

npm cache clean --force

and Install

npm install -g @angular/[email protected]

Upvotes: 3

viztastic
viztastic

Reputation: 1995

npx @angular/cli@10 new my-project

you can replace 10 with your version of choice... no need to uninstall your existing CLI! Just learnt that now...

Upvotes: 50

Nilesh Jadhav
Nilesh Jadhav

Reputation: 1

No need to update angular and all just downgrade material and cdk version to 14.2.7 version which is compatable with Angular 14. Uninstall latest versions : npm uninstall @angular/material @angular/cdk --legacy-peer-deps Install 14.2.7 version npm install @angular/[email protected] --force npm install @angular/[email protected] --force

Upvotes: 0

jdk
jdk

Reputation: 516

Use (replace with version you want to install)

npm install -g @angular/[email protected]

Upvotes: 5

Tanvir Alam
Tanvir Alam

Reputation: 21

You don't need to uninstall your current globally installed angular cli. You can install a specific cli version locally and finish your project. Also, remember that angular cli also depends on a specific version of nodejs. So use nvm to install a specific nodejs version that is compatible with your locally installed angular cli. Follow these steps:

Step 1:

nvm install vX.Y.Z 

where X.Y.Z is nodejs version that is compatible with your angular cli version.

Step 2:

nvm use vX.Y.Z

Step 3:

npx @angular/[email protected] new my-poject 

where X.Y.Z is your desired version

Step 4:

 cd my-project && ng serve

Now angular cli is using locally installed version instead of globally installed cli. You can ignore the version mismatch warnings.

Upvotes: 0

avi.elkharrat
avi.elkharrat

Reputation: 6790

To answer your question, let's assume that you are interested in a specific angular version and NOT in a specific angular-cli version (angular-cli is just a tool after all).

A reasonnable move is to keep your angular-cli version alligned with your angular version, otherwise you risk to stumble into incompatibilities issues. So getting the correct angular-cli version will lead you to getting the desired angular version.

From that assumption, your question is not about angular-cli, but about npm.

Here is the way to go:

[STEP 0 - OPTIONAL] If you're not sure of the angular-cli version installed in your environment, uninstall it.

npm uninstall -g @angular/cli

Then, run (--force flag might be required)

npm cache clean

or, if you're using npm > 5.

npm cache verify

[STEP 1] Install an angular-cli specific version

npm install -g @angular/[email protected]

[STEP 2] Create a project

ng new you-app-name

The resulting white app will be created in the desired angular version.

NOTE: I have not found any page displaying the compatibility matrix of angular and angular-cli. So I guess the only way to know what angular-cli version should be installed is to try various versions, create a new project and checkout the package.json to see which angular version is used.

angular versions changelog Here is the changelog from github reposition, where you can check available versions and the differences.

Upvotes: 195

Junaid
Junaid

Reputation: 4926

Use this command to install any your desired angular version app:
npx -p @angular/cli ng new hello-project

  • Install npx using npm i -g npx if not already installed.

Angular CLI versions indicate which angular version will be installed e.g. @angular/cli@^7.0.0 creates angular 7 projects,
@angular/cli@^9.0.0 creates angular 9 projects &
@angular/cli@latest or just @angular/cli creates latest stabel versioned Angular app.

Upvotes: 2

yHydv
yHydv

Reputation: 31

reinstalling global package is difficult every time instead i do this to manage multiple projects of different angular versions in my workspace.

mkdir <new workspace> 
cd <new workspace>
npm init
npm i @angular/[email protected]

you can use any version

ng -v

Your global Angular CLI version (13.3.2) is greater than your local version (12.2.18). The local Angular CLI version is used.

ng new <project name>
cd <project name>
cat package.json

package.json

you can see the angular version is 12

Upvotes: 3

sakuranasty
sakuranasty

Reputation: 56

Im my case I had nx workspace, where I had another Angular app with old version, so I had @angular/cli installed locally with the older version. So when I tried to add a new app I got warning: Your global Angular CLI version (14.1.2) is greater than your local version (11.2.0). The local Angular CLI version is used.. So, you can install locally whatever version you need and it will be used

Upvotes: 1

Freestyle09
Freestyle09

Reputation: 5508

You can also use npx to generate applications in previous versions

For example:

#Angular 11: last CLI version 11
npx -p @angular/[email protected] ng new Angular11App

Source: https://frontbackend.com/angular/how-to-generate-angular-application-in-a-specific-version-using-ng-new-command

Upvotes: 4

jdev
jdev

Reputation: 5622

just

sudo npm -g install @angular/[email protected]

for list of valid version plz check link below Angular CLi Versions

Upvotes: 2

Vy Do
Vy Do

Reputation: 52508

Use CMD run as administrator, command like this

npm i @angular/[email protected]
npm i -g @angular/[email protected]

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

Get exist version like this https://www.npmjs.com/package/@angular/cli/v/12.2.16

Upvotes: 1

Ruben Acevedo
Ruben Acevedo

Reputation: 101

This work for me.
Open CMD in folder "C:\Users\YourUser\source\repos"

npm uninstall -g @angular/cli 
npm cache clean
npm cache verify
npm install -g @angular/cli

Try again after that.

Upvotes: 2

luqman ahmad
luqman ahmad

Reputation: 199

npm install -g @angular/[email protected]
##Then you can check the version by##
ng --version

https://www.npmjs.com/package/@angular/cli/v/12.1.0

Upvotes: 1

Mario Petrovic
Mario Petrovic

Reputation: 8332

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.

Upvotes: 76

Robert Brisita
Robert Brisita

Reputation: 5844

The angular/cli versions and their installed angular/compiler versions:

  • 1.0 - 1.4.x = ^4.0.0
  • 1.5.x = ^5.0.0
  • 1.6.x - 1.7.x = ^5.2.0
  • 6.x = ^6.0.0
  • 7.x = ^7.0.0

Can be confirmed by reviewing the angular/cli's package.json file in the repository newer repository master repository. One would have to install the specific cli version to get the specific angular version:

npm -g install @angular/[email protected].* # For ^5.0.0

Upvotes: 32

Andrew Koper
Andrew Koper

Reputation: 7199

I have Angular 11 installed globally on my computer, but I needed to create a new project in Angular 6. Based on the CLI version to Angular version info in Robert Brisita's answer on this question, these steps did it for me:

created [angular-six-dir]
cd [angular-six-dir]
npm install @angular/cli@6.* 
ng new [angular-six-project-name]

Upvotes: 4

swetha sasanapuri
swetha sasanapuri

Reputation: 365

npm i -g @angular/[email protected]

x,y,z--> ur desired version number

Upvotes: 8

Anton Krosnev
Anton Krosnev

Reputation: 4122

I would suggest using NVM to keep different versions of node and npm and then install the compatible angular-cli

Upvotes: 1

Rajnikant Lodhi
Rajnikant Lodhi

Reputation: 558

Use the following command to install and downgrade the specific version.
uninstall cli

npm uninstall -g @angular/cli

clean npm cache

 npm cache clean --force

install cli

npm install -g @angular/cli@_choose_your_version

Upvotes: 17

Otman Yazigh
Otman Yazigh

Reputation: 241

Yes, it's possible to install a specific version of Angular using npm:

npm install -g @angular/[email protected]

Next, you need to use the ng new command to create an Angular project based on the specific version you used when installing the CLI:

ng new your-project-name

This will generate a project based on Angular v8.3.19, the version which was specified when installing Angular CLI.

Upvotes: 20

MikeBRal
MikeBRal

Reputation: 449

If you still have problems and are using nvm make sure to set the nvm node environment.

To select the latest version installed. To see versions use nvm list.

nvm use node
sudo npm remove -g @angular/cli
sudo npm install -g @angular/cli

Or to install a specific version use:

sudo npm install -g @angular/[email protected]

If you dir permission errors use:

sudo npm install -g @angular/[email protected] --unsafe-perm

Upvotes: 4

Prajwal Singh
Prajwal Singh

Reputation: 51

Execute this command in the command prompt and you will be good to go

npm install -g @angular/cli@version_name

Upvotes: 2

brijmcq
brijmcq

Reputation: 3418

Edit #2 ( 7/2/2017)

If you install the angular cli right now, you'd probably have the new name of angular cli which is @angular/cli, so you need to uninstall it using

npm uninstall -g @angular/cli

and follow the code above. I'm still getting upvotes for this so I updated my answer for those who want to use the older version for some reasons.


Edit #1

If you really want to create a new project with previous version of Angular using the cli, try to downgrade the angular-cli before the final release. Something like:

npm uninstall -g angular-cli
npm cache clean
npm install -g [email protected]

Initial

You can change the version of the angular in the package.json . I'm guessing you want to use older version of angular but I suggest you use the latest version. Using:

ng new app-name

will always use the latest version of angular.

Upvotes: 40

Rohit Raghav
Rohit Raghav

Reputation: 67

use the following command to install the specific version. say you want to install angular/cli version 1.6.8 then enter the following command :

sudo npm install -g @angular/[email protected]

this will install angular/cli version 1.6.8

Upvotes: 1

Chris Halcrow
Chris Halcrow

Reputation: 31950

Specify the version you want in the 'dependencies' section of your package.json, then from your root project folder in the console/terminal run this:

npm install

For example, the following will specifically install v4.3.4

"dependencies": {
    "@angular/common": "4.3.4",
    "@angular/compiler": "4.3.4",
    "@angular/core": "4.3.4",
    "@angular/forms": "4.3.4",
    "@angular/http": "4.3.4",
    "@angular/platform-browser": "4.3.4",
    "@angular/platform-browser-dynamic": "4.3.4",
    "@angular/router": "4.3.4",
  }

You can also add the following modifiers to the version number to vary how specific you need the version to be:

caret ^

Updates you to the most recent major version, as specified by the first number:

^4.3.0

will load the latest 4.x.x release, but will not load 5.x.x

tilde ~

Update you to the most recent minor version, as specified by the second number:

~4.3.0

will load the latest 4.3.x release, but will not load 4.4.x

Upvotes: 12

Related Questions