100

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.

Francesco Borzi
  • 56,083
  • 47
  • 179
  • 252

10 Answers10

1403

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 (check this for more details):

ng update @angular/cli --from=1.7.4 --migrate-only
Elias Strehle
  • 1,722
  • 1
  • 21
  • 34
Francesco Borzi
  • 56,083
  • 47
  • 179
  • 252
  • 3
    Pedantic alert: You can find more details about changes between versions in the Releases tab on GitHub. Link: https://github.com/angular/angular-cli/releases – Stuti Verma Aug 17 '17 at 05:53
  • If you are experiencing problems using these commands especially on windows machines. Try adding the --on-optional flag on both the npm install and uninstall commands. – Sydwell Nov 07 '17 at 09:59
  • 18
    Update 2017 (npm@5) : if you really need to clean your cache : "npm cache clean --force" – Neyt Nov 10 '17 at 15:14
  • 3
    why uninstall angular-cli and not whole @angular/cli? – YASH DAVE Dec 01 '17 at 11:15
  • This is taken from the official notes. They uninstall angular-cli because it was the name of the package before the version 1.5 (I think), so it's recommended to remove it before installing the package under the new name (@angular/cli). – ssougnez Dec 08 '17 at 12:26
  • 4
    Running the command npm cache clean throws error 'As of npm@5, the npm cache self-heals from corruption issues and data extracted from the cache is guaranteed to be valid. If you want to makesure everything is consistent, use 'npm cache verify' instead.' "if you want to force, you can add --force – crazyCoder Feb 11 '18 at 17:35
  • 1
    @PushkalBoganatham as @neyt stated, you need to use the `--force` flag – svict4 Feb 12 '18 at 00:33
  • Pls. replace 'npm cache clean' with 'npm cache verify' for latest versions of npm. – razvanone Apr 05 '18 at 06:15
  • Post @angular/cli@6.0.0 you only need one single command i.e **ng update @angular/cli** – Abhishek Chandel May 07 '18 at 06:37
  • # updating using npm $ npm i -g @angular/cli $ npm i @angular/cli # using Yarn $ yarn global add @angular/cli $ yarn add @angular/cli – Andre Coetzee May 24 '18 at 06:54
  • This is still working for Angular CLI: 6.1.2 update to Angular CLI: 6.1.3 using Node: 8.11.3 – Damir Varevac Aug 15 '18 at 06:18
  • use --force if terminal not allow to do this like npm cache clean --force – Yasir Shabbir Choudhary Aug 30 '18 at 09:16
  • 2
    Strange, updating from A6 to A7, when installing the @latest version globally, I end up with the same version (6.2.4). On a Mac, NPM 8.9.4. Did a `npm uninstall -g @angular/cli` which removed it globally. But after installing again, I got the same version of 6. – Mattijs Nov 18 '18 at 00:17
  • @Mattijs, I have same problem. But, I am on Windows and I have npm version 6.4.1 . I even used npm cache verify --force and manually deleted the npm/node_modules/@angular folder. – rickz Nov 23 '18 at 19:52
  • 1
    @rickz I ended up installing version`@angular/cli@7.0.4` which worked – Mattijs Nov 25 '18 at 11:18
  • use @next for beta version `npm install -g @angular/cli@next`, @latest for stable version `npm install -g @angular/cli@latest`, and @{{version_code}} for exact version like `npm install -g @angular/cli@7.0.0` – Ravi Sevta Mar 30 '19 at 07:03
  • Just to bring this up to date, here it is from the horse's mouth (which means 'official source'): https://www.npmjs.com/package/@angular/cli#updating-angular-cli – Stewii Apr 03 '21 at 22:25
  • In my case `ng v` command just wasn't reflecting the new version right after `npm i`. Closing the terminal, opening it again and running `ng v` again showed the latest version – Omar Apr 12 '21 at 16:13
  • If you need to upgrade to last version on windows you can: - Open PowerShell Command Prompt as Admin - Set PowerShell Execution Policy : Set-ExecutionPolicy Unrestricted -Scope CurrentUser -Force - Install npm Upgrader Tool : npm install -g npm-windows-upgrade - Upgrade npm Version: npm-windows-upgrade For more information you can check https://linuxhint.com/how-to-update-npm-version-in-windows/ – Otmane el alami el hassani Feb 17 '23 at 12:25
250

First time users:

npm install -g @angular/cli

Update/upgrade:

npm install -g @angular/cli@latest

Check:

ng --version

or Angular 14.X +

ng version

See documentation.

Majies
  • 3
  • 2
Kofi Sammie
  • 3,237
  • 1
  • 17
  • 17
  • 12
    If you don't see the new version after Update/upgrade try closing and reopening the terminal and run `ng --version` again – Omar Apr 12 '21 at 16:39
  • 1
    Thanks. is `@latest` still needed to upgrade in 2021? What happens if I already have an older version of Angular CLI installed globally and don't include the `@latest` tag? – Kyle Vassella Jul 09 '21 at 03:31
  • Yes do that and also in 2021 or yet 2022 you can Run "npx @angular/cli@13 update @angular/core@13 @angular/cli@13" which should bring you to version 13 of Angular since Angular now uses TypeScript 4.4 and is version 13. https://update.angular.io/?l=3&v=12.0-13.0 – Kofi Sammie Jan 08 '22 at 07:10
162

ng6+ -> 7.0

Update RxJS (depends on RxJS 6.3)

npm install -g rxjs-tslint
rxjs-5-to-6-migrate -p src/tsconfig.app.json

Remove rxjs-compat

Then update the core packages and Cli:

ng update @angular/cli @angular/core

(Optional: update Node.js to version 10 which is supported in NG7)

ng6+ (Cli 6.0+): features simplified commands

First, update your Cli

npm install -g @angular/cli
npm install @angular/cli
ng update @angular/cli

Then, update your core packages

ng update @angular/core

If you use RxJS, run

ng update rxjs

It will update RxJS to version 6 and install the rxjs-compat package under the hood.

If you run into build errors, try a manual install of:

npm i rxjs-compat
npm i @angular-devkit/build-angular

Lastly, check your version

ng v

Note on production build:

ng6 no longer uses intl in polyfills.ts

//remove them to avoid errors
import 'intl';
import 'intl/locale-data/jsonp/en';

ng5+ (Cli 1.5+)

npm install @angular/{animations,common,compiler,compiler-cli,core,forms,http,platform-browser,platform-browser-dynamic,platform-server,router}@next typescript@2.4.2 rxjs@'^5.5.2'
npm install typescript@2.4.2 --save-exact

Note:

  1. The supported Typescript version for Cli 1.6 as of writing is up to 2.5.3.
  2. Using @next updates the package to beta, if available. Use @latest to get the latest non-beta version.

After updating both the global and local package, clear the cache to avoid errors:

npm cache verify (recommended)
npm cache clean (for older npm versions)

Here are the official references:

  1. Updating the Cli
  2. Updating the core packages core package.
Scottie
  • 11,050
  • 19
  • 68
  • 109
Pageii Studio
  • 2,086
  • 1
  • 15
  • 18
  • 4
    `npm cache clean --force` Really helped me – Pini Cheyni Nov 24 '17 at 21:48
  • 1
    Why oh why is this part no in the release notes! – Drenai Jan 15 '18 at 16:38
  • can you please confirm what you said about RxJS 6 being deprecated. Everywhere I look it appears that v6 is the latest stable release https://github.com/ReactiveX/rxjs https://rxjs-dev.firebaseapp.com/ – Joey Gough Oct 31 '18 at 10:12
  • 1
    @JoeyGough nice catch! Ng7 depends on rxjs 6.3. Thanks for your comment. ref: https://github.com/angular/angular/blob/master/CHANGELOG.md#user-content-700-2018-10-18 – Pageii Studio Oct 31 '18 at 10:30
50

The following approach worked for me:

npm uninstall -g @angular/cli

then

npm cache verify

then

npm install -g @angular/cli

I work on Windows 10, sometimes I had to use: npm cache clean --force as well. You don't need to do if you don't have any problem during the installation.

Enayat
  • 3,904
  • 1
  • 33
  • 47
49

The powerful command installs and replaces the last package.

I had a similar problem. I fixed it.

 npm install -g @angular/cli@latest

and

npm install --save-dev @angular/cli@latest

enter image description here

BehrouzMoslem
  • 9,053
  • 3
  • 27
  • 34
41

This command works fine:

npm upgrade -g @angular/cli
Derlin
  • 9,572
  • 2
  • 32
  • 53
wdavilaneto
  • 788
  • 6
  • 7
23

Note 22 Feb 2023: There is a great tool that was recently released called NGVM.
It might be really helpful maintaining Angular CLI versions.

If you have any difficulties managing your global CLI versions it is better to use a tool for that. Here is a few options:

NVM for MAC / Windows or Volta


To update the local CLI in your Angular project follow this steps:

Starting from CLI v6 you can just run ng update in order to get your dependencies updated automatically to a new version.

ng update @angular/cli

With ng update sometimes you might want to add --force flag.

You can also pass --all flag to upgrade all packages at the same time.

ng update --all --force

If you want just to migrate CLI just run this:

ng update @angular/cli --migrateOnly

You can also pass flag --from=from- version from which to migrate from, e.g --from=1.7.4. This flag is only available with a single package being updated, and only on migration only.

After update is done make sure that the version of typescript you got installed supported by your current angular version, otherwise you might need to downgrade the typescript version. Also bear in mind that usually the latest version of angular won't support the latest version of the typescript.

Checkout Angular CLI / Angular / NodeJS / Typescript compatibility versions here

Also checkout this guide Updating your Angular projects and update.angular.io


OLD ANSWER:
All you need to do is to diff with angular-cli-diff and apply the changes in your current project.

Here is the steps:

  1. Say you go from 1.4. to 1.5 then you do https://github.com/cexbrayat/angular-cli-diff/compare/1.4.0...1.5.0
  2. click on File changed tab
  3. Apply the changes to your current project.
  4. npm install / yarn
  5. Test all npm scripts (more details here: https://stackoverflow.com/a/45431592/415078)
angularrocks.com
  • 26,767
  • 13
  • 87
  • 104
17

In addition to @ShinDarth answer.

I did what he said but my package did not updated the angular version, and I know that this post is about angular-cli, but i think that this can help too.

  • so after doing what @ShinDarth said above, to fix my angular version I had to create a new project with -ng new projectname that generated a package.
  • copy the new package, then paste the new package on all projects packages needing update (remember to add the dependencies you had and change the name on first line) or you can just change the versions manualy without copy and paste.
  • then run -npm install.

Now my ng serve is working again, maybe there is a better way to do all that, if someone know, please share, because this is a pain to do with all projects that need update.

Alexander Abakumov
  • 13,617
  • 16
  • 88
  • 129
13

To update Angular CLI to a new version, you must update both the global package and your project's local package.

Global package:

npm uninstall -g @angular/cli
npm cache verify
# if npm version is > 5 then use `npm cache verify` to avoid errors (or to avoid using --force)
npm install -g @angular/cli@latest

Local project package:

rm -rf node_modules dist # use rmdir /S/Q node_modules dist in Windows Command Prompt; use rm -r -fo node_modules,dist in Windows PowerShell
npm install --save-dev @angular/cli@latest
npm install

Source: Github

Rap
  • 6,851
  • 3
  • 50
  • 88
Hasan Fathi
  • 5,610
  • 4
  • 42
  • 60
13

In my case, I have installed angular-cli locally using npm install --save-dev angular-cli.
So, when I use command npm install -g @angular/cli, it generates error saying

Your global Angular CLI version (1.7.3) is greater than your local version (1.4.9)

Please note that angular-cli, @angular/cli and @angular/cli@latest are two different cli's.
What solves this is uninstall all cli and then install latest angular cli using

npm install -g @angular/cli@latest
Random
  • 3,158
  • 1
  • 15
  • 25
ARKhan
  • 1,724
  • 22
  • 30