Angular, Node, NVM, and NPM - node.js

I installed Node version v6.5.0 a few days ago and with this installation came npm v3.10.3.
Today I updated Node to v8.9.4 using nvm install 8.9.4 and it came with corresponding version of npm (can't remember the exact version number).
Here are my questions:
After installing Node 8.9.4, I listed all Node versions and it shows both versions correctly. I then do nvm use 8.9.4 and output shows as -> Now using node v8.9.4 (64-bit).
However, when I do node -v, it still shows v6.5.0 and not v8.9.4 that I switched to. Why? It should show v8.9.4
How do I change version of npm from v3.10.3 (that came with Node v6.5.0) to the latest version (that came with v8.9.4)?
How do I list all npm versions on my machine?
Will Angular CLI v1.7.0 work with both Node v6.5.0 and v8.9.4?

You may "use" the node version you want:
$ nvm use 8.9.4
but, if you want to set it as default:
$ nvm alias default 8.9.4
When using the version of node you want, just run:
$ npm install -g npm
NVM have "node" versions: nvm list. For each version of node, there is a npm version associated. You need to use (step 1) each one and run `npm -v'
Don't know.

Related

NPM is not compatible with node 8.x

I know that version node 8.x is very old but I need works with project of this version on node. I installed a few version node 8.x with this website https://nodejs.org/en/download/releases/ . As you know npm is installed together with node so everything should be ok, I thought. But in my case which I tryed type npm install or npm --version, etc. npm returned error that node version is so old I shoud install newer which is not an option. Any ideas how can I use nodejs 8.x with npm?

nvm / node / npm: newer npm with node 12 than with node 14?

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?
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 npm#6.14.16

Why does upgrading npm not actually update it?

I'm on Mac OS X (High Sierra). I'm having trouble upgrading npm. From their docs, I ran
localhost:tmp davea$ npm install -g npm#latest
/usr/local/Cellar/node#8/8.16.1/bin/npm -> /usr/local/Cellar/node#8/8.16.1/lib/node_modules/npm/bin/npm-cli.js
/usr/local/Cellar/node#8/8.16.1/bin/npx -> /usr/local/Cellar/node#8/8.16.1/lib/node_modules/npm/bin/npx-cli.js
+ npm#6.11.3
updated 1 package in 6.56s
but when I check the version, it is still at 6.9.0
localhost:tmp davea$ npm -v
6.9.0
What's going on?
You are looking at the npm version which is different to the node version.
If you look at the releases from nodejs.org you can see which version of npm your version of node relates to.
If you type node -v you'll see your Node version.
8.6.1 relates to npm version 6.4.1.
npm version 6.9.1 was released with node version 10.16.0
I would highly recommend using nvm on OSX to take the stress out of it. You can find it here.
Also, try looking at this answer.

downgrade NPM version on mac

I'm trying to downgrade my NPM version from 6.5.0 -> 6.2.0 (i'm on MAC OS)
running npm install -g npm#6.2.0
however it still shows version 6.5.0 in the terminal with npm -v (also after reboot)
Something i'm missing here ? i want to be able to switch between versions with easy, preferably not by reinstalling Node and NPM each time.
Best use nvm, the Node package manager. You can effortlessly switch between Node versions and their matching npm versions.
Try which npm and check your .profile and .bashrc files, maybe you have a specific npm path in there?

How to have a different version of npm for a particular version of Node.js?

If the requirement is to use Node.js v4.x, and npm v3.x, I was able to use
nvm install --lts=argon
to install Node v4.8.3 LTS. But on the Node / npm release page, it says Node v4.8.3 comes with npm 2.15.11. And npm 3.x comes with only Node v5.x.
In this case, how can we make npm v3.x while keeping Node at version 4.x?
(and since npm v3.x can be 3.3.6 to 3.10.10, which version should be installed?)
I think I found the answer. It is to use npm install to upgrade itself:
npm install npm#3.10.10 -g
(or any version you want).

Resources