Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to Change (Upgrade or Downgrade) Angular version?

I have recently installed Angular 6 and would like to go back to using Angular 5.2 How can I change my Angular version from whatever version I have to whichever one I choose?

like image 776
Matias Miraglio Avatar asked May 18 '18 16:05

Matias Miraglio


3 Answers

I will try to give a general answer for future similar issues.

The version of angular used in a project is determined by the version of angular cli installed. Any specific version of angular cli can be installed with the following command:

npm install --global @angular/[email protected].

example:

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

even if you have another version of angular cli (either newer or older) installed. That should not cause issues. However to be sure you can use:

npm uninstall -g angular-cli

npm cache clean

npm install -g [email protected]

like image 95
Matias Miraglio Avatar answered Nov 15 '22 21:11

Matias Miraglio


First you need to uninstall, install the cli

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

After this, delete node_modules directory

Then change your package versions in package.json to have versions like the following

{
  ...
  },
  ...
  "dependencies": {
    "@angular/animations": "5.2.2",
    "@angular/cdk": "^5.2.2",
    "@angular/common": "5.2.2",
    "@angular/compiler": "5.2.2",
    "@angular/core": "5.2.2",
    "@angular/forms": "5.2.2",
    "@angular/http": "5.2.2",
    "@angular/material": "^5.2.2",
    "@angular/platform-browser": "5.2.2",
    "@angular/platform-browser-dynamic": "5.2.2",
    "@angular/router": "5.2.2",
    "@ngrx/core": "^1.2.0",
    "@ngrx/store": "^4.0.3",
    "core-js": "^2.5.1",
    "hammerjs": "^2.0.8",
    "rxjs": "^5.5.2",
    "typescript": "^2.4.2",
    "web-animations-js": "^2.3.1",
    "zone.js": "^0.8.18"
  },
  "devDependencies": {
    "@angular/cli": "1.6.1",
    "@angular/compiler-cli": "5.2.2",
    "@angular/language-service": "5.2.2",
    "@types/jasmine": "~2.5.53",
    "@types/jasminewd2": "~2.0.2",
    "@types/node": "~6.0.60",
    ...
  }
}

and install packages

npm install
like image 39
Lucas Avatar answered Nov 15 '22 22:11

Lucas


Check the version currently installed by:

# ng version

Angular CLI: 12.1.0
Node: 12.18.4
Package Manager: npm 6.14.6
OS: linux x64

Angular: 12.2.10
... animations, common, compiler, compiler-cli, core, forms
... google-maps, platform-browser, platform-browser-dynamic
... router

Package                         Version
---------------------------------------------------------
@angular-devkit/architect       0.1201.0
@angular-devkit/build-angular   12.1.0
@angular-devkit/core            12.1.0
@angular-devkit/schematics      12.1.0
@angular/cdk                    12.1.0
@angular/cli                    12.1.0
@angular/language-service       12.1.0
@schematics/angular             12.1.0
rxjs                            6.6.2
typescript                      4.2.3
    

then proceed with installation to your project rather than using -g or --global

The --save option instructs NPM to include the package inside of the dependencies section of your package.json automatically, thus saving you an additional step.

ie;

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

if you want to use global then,

npm i -g @angular/[email protected]

Reference: What is the --save option for npm install?

like image 35
Shaze Avatar answered Nov 15 '22 21:11

Shaze