ng update to specific version

Viewed 44389

I would like to update Angular from version 5.0 to version 6.1. The instructions at https://update.angular.io/ suggest using ng update @angular/core to update. However this updates directly to version 7 instead of version 6.

The ng update docs suggest that using --to would update to a specific version. However this does not seem to work. The exact command used is: ng update @angular/core --to 6.1.0 But this updates to 7.0.0

EDIT:

I've tried using --from=5.0.0 --to=6.1.9 but this didn't work. I've noticed we're stil using angular-cli version 1.6.4. This version supports --next which according to the docs should (Default: false) Install the next version, instead of the latest. However this changes the package.json to use version 7.0.0 of all @angular/* packages

5 Answers

Adding this here, since this comes up in search results and the answers provided here didn't work for me.

What worked for me was using ng update @angular/core@7.0.0. This should probably be noted in the Angular Update Guide (https://update.angular.io/), but it's not. Since that page throws a notice up when upgrading across more than one major version at a time, but using the recommended command ng update @angular/core upgrades to the latest release (which could be across more than one major version), perhaps this should be changed.

You can use the @ symbol to specify the version on each package desired. The currently recommend approach to upgrading Angular to a newer version (or version you dictate) is to use the following command:

ng update @angular/cli @angular/core

In this case let's say I wanted to upgrade to 8.1.1 instead of the latest version of 8.2.0 I would use the following:

ng update @angular/cli@8.1.1 @angular/core@8.1.1

This is the same way you specify a specific version when doing any npm installs as explained here.

This answer is now outdated. Please see the proper way to update https://angular.io/cli/update

Perform a basic update to the current stable release of the core framework and CLI by running the following command.

ng update @angular/cli @angular/core

To update to the next beta or pre-release version, use the --next option.

To update from one major version to another, use the format

ng update @angular/cli@^<major_version> @angular/core@^<major_version>

We recommend that you always update to the latest patch version, as it contains fixes we released since the initial major release. For example, use the following command to take the latest 10.x.x version and use that to update.

ng update @angular/cli@^10 @angular/core@^10

For detailed information and guidance on updating your application, see the interactive Angular Update Guide -> https://update.angular.io/

If you are upgrading to an older version, as recommended by Angular to upgrade to the next major version first instead of moving directly to the latest version (like current latest version is v10 and you are upgrading from v8, its recommended to first upgrade to v9 and then to v10), then you have to provide the update the dependencies/package to the latest version compatible with Angular9.

For upgrading, first check the required dependencies to be updated with the help of

ng update - which will list all the dependencies you have to update(see image)ng update command

Referring to the picture, there are 6 packages to update which we will update to the version we are upgrading to(in this case it is v9) using ng update command:

ng update @angular/cdk@9 @angular/cli@9 @angular/core@9 @angular/material@9 @ngx-pwa/local-storage@9 rxjs --force

(you can define specific versions of the packages by going to npm packages, for example - @angular/core@9.1.2 as 9.1.2 is the latest stable release of @angular/core package for angular9).

This will update your project to angular v9.

Similarly, for v10, you need to follow the above process.

[Note: For the latest angular version(which is v10 at the time of writing this), you need not provide the version during update and you can directly update as:

ng update @angular/cdk @angular/cli --force

You can also use npm outdated to view the outdated packages which needs to be updated.

Hope this answer proves helpful for you. If you find any issues, please comment and I'll try to provide solution.

To Remove Circular Dependencies For all updation and avoiding the circular dependencies (no need to use ng update @angular/cli@8.1.1 @angular/core@8.1.1 etc etc), in general, use the below command
ng update --force --all

Related