Why does upgrading npm not actually update it? - node.js

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.

Related

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

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?

Angular, Node, NVM, and NPM

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.

npm does not support Node.js v9.0.0

I just upgraded my project to use Node.js v9.0.0. When I start my project using npm, it tells me I should upgrade to a newer Node version, but I believe this is the newest version. I also believe I'm on the newest version of npm (5.5.1).
Do I need to worry about this warning? Is there a good way to resolve the issue?
Here's the full warning:
npm WARN npm npm does not support Node.js v9.0.0
npm WARN npm You should probably upgrade to a newer version of node as we
npm WARN npm can't make any promises that npm will work with this version.
npm WARN npm Supported releases of Node.js are the latest release of 4, 6, 7, 8.
npm WARN npm You can find the latest version at https://nodejs.org/
Now using node v9.0.0 (npm v5.5.1)
I've just upgraded to Node v9 and ran into the same issue. There's a Github issue for this here.
Following the advice to uninstall a global instance of npm has resolved the issue for me, using:
npm uninstall -g npm
With Node 10.6.0 on Windows 10 with Git Bash installed, I did this and all worked well:
1. Launch Git Bash terminal.
2. cd ~/AppData/Roaming
3. rm -rf npm
4. rm -rf npm-cache
5. npm install -g npm#latest
Check version and test on an existing project to verify (cd to project dir)...
6. npm -version
7. npm install
NB: Performing steps 2 through 4 via Windows Explorer could be faster.
9.0.0 is indeed the latest version available at the moment. The reason that NPM shows you this message is because NPM hasn't updated their unsupported.js yet to accept 9.0.0 as a supported version.
I would say that you can probably use it without problems, but if you stumble upon one, know that it's probably caused by a breaking change in Node.js 9.0.0 and will very likely be fixed by the NPM team soon.
npm does not support Node.js v9.1.0
Uninstall did not work for me
npm uninstall -g npm
Node.js v9.1.0 comes bundled with npm v5.5.1. The latest version of npm is also v5.5.1, however, the version bundled with Node.js isn't exactly the same as the original version from npm.
The following is what I needed to do on MacOS
To completely uninstall node + npm, do the following:
1. go to /usr/local/lib and delete any node and node_modules.
2. go to /usr/local/include and delete any node and node_modules directory.
3. download and install node from nodejs.org
Latest update Jan 2018: NPM has released version 5.6.0 to work with this.
How to upgrade npm:
Note if you are using node version 9 you will not be able to upgrade npm directly, since npm does not support version 9, so using nvm, downgrade node to latest stable release, that will make npm work, then use commandnpm install -g npm#latest to upgrade npm.
Install nvm:
curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.33.8/install.sh | bash\n
export NVM_DIR="$HOME/.nvm"\n[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"
Download and use node X version:
nvm install 4.4.2
nvm use 4.4.2
node -v
[sudo] npm install -g npm#5.3.x remove this problem for me. ubuntu 16.10

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