Angular CLI − ng update Command



This chapter will discuss the Angular CLI ng update command. It also includes its syntax, arguments, options, and a few examples that show how to use it in an Angular application.

The 'ng update' Command

The Angular CLI (Command Line Interface) provides a command named "ng update" to update your Angular application and its dependencies.

Syntax

Following is the syntax of the Angular CLI ng update command −

ng update ng[packages..] [options]

Here,

  • packages: The names of package(s) need to be updated.
  • options: These are the optional flags (options) that modify the behavior of the command.

Arguments

The argument for ng update command is as follows −

Sr.No. Argument & Description
1

The names of package(s) to update.

Options

Below is a list of a few commonly used options (flags) with this command −

Sr.No. Option & Description
1 --all=true|false

Whether to update all packages in package.json.

Default: false

2 --allowDirty=true|false

Whether to allow updating when the repository contains modified or untracked files.

3 --createCommits=true|false

Create source control commits for updates and migrations.

Default: false

Aliases: -C

4 --force=true|false

If false, will error out if installed packages are incompatible with the update.

Default: false

5 --from=from

Version from which to migrate from. Only available with a single package being updated, and only on migration only.

6 --help=true|false|json|JSON

Shows a help message for this command in the console.

Default: false

7 --migrateOnly=true|false

Only perform a migration, does not update the installed version.

8 --next=true|false

Use the largest version, including beta and RCs.

Default: false

9 --packages

The names of package(s) to update.

10 --to=to

Version up to which to apply migrations. Only available with a single package being updated, and only on migrations only. Requires from to be specified. Default to the installed version detected.

11 --verbose=true|false

Display additional details about internal operations during execution.

Default: false

Example 1

This is a basic example of the "ng update" command. Use the following command to update the current Angular application and its dependencies −

ng update

Once the above command runs successfully, it will display the following output in your terminal:

Using package manager: npm
Collecting installed dependencies...
Found 21 dependencies.
    We analyzed your package.json, there are some packages to update:

      Name                               Version                  Command to update
     --------------------------------------------------------------------------------
      @angular/cli                       19.2.3 -> 19.2.4         ng update @angular/cli
      @angular/core                      19.2.2 -> 19.2.3         ng update @angular/core

    There might be additional packages which don't provide 'ng update' capabilities that are outdated.     
    You can update the additional packages by running the update command of your package manager.

Example 2

In the following example, we are performing a basic update to the current stable release of the core framework and CLI by running the command below −

ng update @angular/cli @angular/core

The following is the output:

The installed Angular CLI version is outdated.
Installing a temporary Angular CLI versioned 19.2.4 to perform the update.
Using package manager: npm
Collecting installed dependencies...
Found 21 dependencies.
Fetching dependency metadata from registry...
    Updating package.json with dependency @angular-devkit/build-angular @ "19.2.4" (was "19.2.3")...
    Updating package.json with dependency @angular/cli @ "19.2.4" (was "19.2.3")...
    Updating package.json with dependency @angular/compiler-cli @ "19.2.3" (was "19.2.2")...
    Updating package.json with dependency @angular/common @ "19.2.3" (was "19.2.2")...
    Updating package.json with dependency @angular/compiler @ "19.2.3" (was "19.2.2")...
    Updating package.json with dependency @angular/core @ "19.2.3" (was "19.2.2")...
    Updating package.json with dependency @angular/forms @ "19.2.3" (was "19.2.2")...
    Updating package.json with dependency @angular/platform-browser @ "19.2.3" (was "19.2.2")...
    Updating package.json with dependency @angular/platform-browser-dynamic @ "19.2.3" (was "19.2.2")...   
    Updating package.json with dependency @angular/router @ "19.2.3" (was "19.2.2")...
UPDATE package.json (1000 bytes)
✔ Cleaning node modules directory
✔ Installing packages
Advertisements