如何将 Angular CLI 升级到最新版本 [英] How to upgrade Angular CLI to the latest version

查看:35
本文介绍了如何将 Angular CLI 升级到最新版本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用 ng --version 我得到:

@angular/cli: 1.0.0

@angular/cli: 1.0.0

这不是可用的最新版本.

which is not the latest release available.

由于我在系统上全局安装了 Angular CLI,为了升级它,我尝试了:

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

npm 更新 angular-cli -g

但它不起作用,因为它停留在 1.0.0 版本.

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

推荐答案

在阅读了 GitHub 存储库报告的一些问题后,我找到了解决方案.

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

为了更新系统中全局安装的 angular-cli 包,您需要运行:

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

根据您的系统,您可能需要在上述命令前加上 sudo.

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

感谢 grizzm0 上指出这一点GitHub.

更新 CLI 后,您可能还想更新 Angular 版本.

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

注意:如果您要从旧版本更新到 Angular CLI 6+,您可能需要阅读 这个.

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

编辑:此外,如果您仍然使用 1.x 版本的 cli,则需要将 angular-cli.json 转换为 angular.json,您可以使用以下命令(检查 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

这篇关于如何将 Angular CLI 升级到最新版本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆