无法更新 Angular CLI

Fro*_*maz 3 npm node-modules angular-cli angular

如您所见,我定期安装版本 9。

\n\n
npm install -g @angular/cli\nnpm WARN deprecated request@2.88.2: request has been deprecated, see https://github.com/request/request/issues/3142\n/home/user/.npm-global/bin/ng -> /home/user/.npm-global/lib/node_modules/@angular/cli/bin/ng\n\n> @angular/cli@9.1.1 postinstall /home/user/.npm-global/lib/node_modules/@angular/cli\n> node ./bin/postinstall/script.js\n\n+ @angular/cli@9.1.1\nupdated 1 package in 8.412s\n\n\xe2\x94\x8c\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x90\n\xe2\x94\x82                 npm update check failed                 \xe2\x94\x82\n\xe2\x94\x82           Try running with sudo or get access           \xe2\x94\x82\n\xe2\x94\x82          to the local update config store via           \xe2\x94\x82\n\xe2\x94\x82 sudo chown -R $USER:$(id -gn $USER) /home/user/.config  \xe2\x94\x82\n\xe2\x94\x94\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x98\nuser@computer:~$ npm list -g\n/home/user/.npm-global/lib\n\xe2\x94\x9c\xe2\x94\x80\xe2\x94\xac @angular/cli@9.1.1\n
Run Code Online (Sandbox Code Playgroud)\n\n

但是当我使用“ng new app-name”创建新应用程序时,我会安装版本 8。当我使用“ng --version”检查版本时,它表示已安装 v8。

\n\n
ng --version    \n\nAngular CLI: 8.0.3\nNode: 12.16.2\nOS: linux x64\nAngular: \n... \n\nPackage                      Version\n------------------------------------------------------\n@angular-devkit/architect    0.800.3\n@angular-devkit/core         8.0.3\n@angular-devkit/schematics   8.0.3\n@schematics/angular          8.0.3\n@schematics/update           0.800.3\nrxjs                         6.4.0\n
Run Code Online (Sandbox Code Playgroud)\n\n

谁能帮我?

\n

Lot*_*re1 9

用户注意事项nvm

nvm如果在安装之前您已经@angular/cli全局安装并且现在使用通过 nvm 安装的不同节点版本,那么您可能会发现以下注释很有用:

nvm当您通过安装全局 node_modules 的 npm 文件夹位置切换节点版本时。

假设我切换到节点 14 ( nvm use 14) 并使用以下命令安装了最新的 Angular cli:

npm install @angular/cli -g

您将看到一个输出,告诉您 Angular 已成功安装。然后你运行 ng --version验证版本,你发现旧版本仍然存在。为什么?

NVM's节点位于: /Users/<USER_NAME>/.nvm/versions/node/v14.XX.XX/bin

@angular/cli全局安装后,ng快捷方式/符号链接将放置在此文件夹中。

lrwxr-xr-x  1 X  staff        39 14 Ago 10:45 ng -> ../lib/node_modules/@angular/cli/bin/ng
-rwxr-xr-x  1 X  staff  76198080 11 Ago 06:29 node
lrwxr-xr-x  1 X  staff        38 14 Ago 10:42 npm -> ../lib/node_modules/npm/bin/npm-cli.js
lrwxr-xr-x  1 X  staff        38 14 Ago 10:42 npx -> ../lib/node_modules/npm/bin/npx-cli.js
Run Code Online (Sandbox Code Playgroud)

因此,它指向节点 14 node_modules 文件夹,该文件夹位于: /Users/<USER_NAME>/.nvm/versions/node/v14.XX.XX/lib/node_modules

但由于我在安装 nvm 之前已经全局安装了 @angular/cli,所以旧版本正在使用中

node_modules要解决此问题,您必须在安装 NVM 之前找到全局的安装位置。就我而言,路径是: /usr/local/lib/node_modules

转到该文件夹​​并删除@angular. 重新启动终端并运行ng --version. 您现在应该获得正确的 ng 版本。

这也适用于其他模块。