I'm using nvm to build libraries that require specific (different) Node versions.
When I do:
nvm use 12
I get:
Now using node v12.21.0 (npm v8.14.0)
But when I do:
nvm use 14
I get:
Now using node v14.18.1 (npm v6.14.15)
I'm very surprised to see an older npm version with a newer Node version. Is that the way it's supposed to be?
When I do nvm use 14
I'd expect it uses the latest Node 14.x with whatever latest npm version is available for that Node version. Or am I misunderstanding how this works?
CodePudding user response:
Node.js is distributed with a version of npm
, but npm
is still a seperate package that can be upgraded.
The distributed versions can be retrieved from node release info
node npm
v12.22.12 6.14.16
v14.20.0 6.14.17
v16.17.0 8.15.0
v18.9.0 8.19.1
npm
can prompt you to upgrade when it detects an old version, and you will also to run into this instruction in the wild a fair bit:
npm install -g npm
This will grab whatever the latest version of npm
is and is likely what happened in the nvm 12
environment.
Sometimes moving to a new major version of npm
can be a source of trouble for projects that have already been setup with a previous major npm
release and some behaviour changes. CI tasks often have a npm install -g npm
and one day they start falling over for what seems like no change. I've also seen npm drop support for an old version of node, so a npm install -g npm
ends up with a broken npm.
If you want to keep a fixed major release, like v6 that Node 12 was release with, use:
npm install -g npm@^6
or to use a specific version
npm install -g [email protected]