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

Viewed 5746

I'm working on a gcloud compute instance running ubuntu 18.04 lts minimal and have installed 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. When I append sudo, it runs but npm -v returns 3.5.2 and not the latest version. 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
1 Answers

For me it worked by doing following steps:

sudo npm install -g npm

Close the terminal. Open a new terminal and check by npm -v

It should work, the terminal doesn't show the updated version in ongoing terminal, it needs a reopen to reflect the changes

Related