简体   繁体   English

如何将npm版本升级到最新版本? Ubuntu显示安装成功,但未升级版本

[英]How to upgrade npm version to latest? Ubuntu shows successful install but doesn't upgrade version

I'm working on a gcloud compute instance running ubuntu 18.04 lts minimal and have installed npm. 我正在运行最小运行ubuntu 18.04 lts的gcloud计算实例,并已安装npm。 However, apt-get install npm came up with 3.5.2, and when I do npm install npm@latest -g , it shows that I have to run as administrator. 但是,apt-get install npm带有3.5.2,当我执行npm install npm@latest -g ,它表明我必须以管理员身份运行。 When I append sudo, it runs but npm -v returns 3.5.2 and not the latest version. 当我追加sudo时,它会运行,但是npm -v返回3.5.2,而不是最新版本。 Why is this so? 为什么会这样呢?

engineering@test2:~$ sudo npm install npm@latest -g
/usr/local/bin/npm -> /usr/local/lib/node_modules/npm/bin/npm-cli.js
/usr/local/bin/npx -> /usr/local/lib/node_modules/npm/bin/npx-cli.js
+ npm@6.4.1
added 274 packages, removed 363 packages and updated 43 packages in 8.462s
engineering@test2:~$ npm -v
3.5.2

For me it worked by doing following steps: 对我来说,它通过执行以下步骤来工作:

sudo npm install -g npm sudo npm install -g npm

Close the terminal. 关闭终端。 Open a new terminal and check by npm -v 打开一个新终端,并通过npm -v检查

It should work, the terminal doesn't show the updated version in ongoing terminal, it needs a reopen to reflect the changes 它应该可以工作,终端不会在进行中的终端中显示更新的版本,需要重新打开以反映更改

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM