How to upgrade Angular CLI to the latest version

Francesco Borzi picture Francesco Borzi · May 12, 2017 · Viewed 573.4k times · Source

Using ng --version I got:

@angular/cli: 1.0.0

which is not the latest release available.

Since I have Angular CLI globally installed on my system, in order to upgrade it I tried:

npm update angular-cli -g

But it does not work, because it stays to 1.0.0 version.

Answer

Francesco Borzi picture Francesco Borzi · May 12, 2017

After reading some issues reported on the GitHub repository, I found the solution.

In order to update the angular-cli package installed globally in your system, you need to run:

npm uninstall -g @angular-cli
npm install -g @angular/cli@latest

Depending on your system, you may need to prefix the above commands with sudo.

Also, most likely you want to also update your local project version, because inside your project directory it will be selected with higher priority than the global one:

rm -rf node_modules
npm uninstall --save-dev @angular-cli
npm install --save-dev @angular/cli@latest
npm install

thanks grizzm0 for pointing this out on GitHub.

After updating your CLI, you probably want to update your Angular version too.

Note: if you are updating to Angular CLI 6+ from an older version, you might need to read this.

Edit: In addition, if you were still on a 1.x version of the cli, you need to convert your angular-cli.json to angular.json, which you can do with the following command:

ng update @angular/cli --from=1.7.4 --migrate-only

(check this for more details).