2

My problem, i can't install my packages or upgrade npm via "npm install -g npm@latest" - because of this problem.

  • ERROR: npm is known not to run on Node.js v10.19.0 You'll need to upgrade to a newer Node.js version in order to use this version of npm. You can find the latest version at https://nodejs.org/

I've installed newest version of node. currently node -v shows v16.15.1 but npm still thinking i'm using an old one. How to update my npm's node version?. P.S. My current OS is Ubuntu 20.08

  • `apt purge nodejs` and then re-install with nodesource prebuild binary: https://github.com/nodesource/distributions#debinstall – Marc Jun 11 '22 at 20:18

3 Answers3

5

because npm is installed via shim. You must do this steps

  • uninstall distribution npm and nodejs (prevent future conflict)
  • remove the npm in shim wich is installed manually (for example with some aws frameworks in my case) with added configs
  • clean package cache (optional)
  • install distribution version nodejs and npm
  • upgrade nodejs ofically
sudo -i
apt remove --purge nodejs npm
apt clean
rm-rf /usr/local/{lib/node{,/.npm,_modules},bin,share/man}/npm*
apt install npm nodejs
npm cache clean -f
npm install -g n
n stable
exit
Rainbof
  • 51
  • 2
2

Duplicate of: https://askubuntu.com/a/1382566/391310

Short Answer

The simplest is to update to Node.js v12:

curl -fsSL https://deb.nodesource.com/setup_12.x | sudo -E bash -
sudo apt-get install -y nodejs

Long Answer

You could update to newer Node.js-versions, see: https://github.com/nodesource/distributions#readme however according to a comment on github, jumping to the newest version, might lead to breaking changes. (I don't notice any.)

Thanks to a comment from @SaidbakR below : To see which version is compatible check the following table:


| NodeJS  | `npm --version` |
|---------|-----------------|
| Node 16 | 6.0+            |
| Node 14 | 4.14+           |
| Node 12 | 4.12+           |
| Node 10 | 4.9+, <6.0      |

I skipped the uneven numbers, because they don't have a long-term-support. Node 18 is as of May 2022 in a prerelease state.

If you would like to update to e.g. Node.js 16, edit the number from the code above:

curl -fsSL https://deb.nodesource.com/setup_16.x | sudo -E bash -
sudo apt-get install -y nodejs

This answer is based on (How to update node.js) as well on (compatible node.js and npm-Versions)

notandy
  • 3,330
  • 1
  • 27
  • 35
0

npm cache clean -f and then npm install -g npm@latest

Ignasi
  • 5,887
  • 7
  • 45
  • 81