44

When I do a npm -v I see that I am still on 5.6.0. And keep getting prompts to do a npm i npm.

But I've done a sudo npm install npm@latest -g and double checked with a npm outdated -g --depth=0 to see that my global npm is at the latest already (6.0.0).

How do I resolve this conflict? Is the npm I'm using the latest or is it still the old one? Is it because my global is linked incorrectly or something?

Kelvin Zhao
  • 2,243
  • 3
  • 22
  • 31

19 Answers19

40

Try closing the Terminal - once you open it again it should work, worked for me well.

*IvanD wrote this solution in a comment to the original post, I thought it's worth an answer post.

Eking
  • 758
  • 8
  • 16
  • Thought I'd just add closing and opening, logging out and back in, shutting off and on the computer doesn't solve this issue. Apparently there was some hard pathing/aliasing issue happening. Only uninstalling and reinstalling node worked. – Kelvin Zhao Jun 12 '20 at 00:35
30

I can 100% vouch this works.

I got this from someone who teaches node.js.

Give NVM (Node Version Manager) a try. Do the commands in the following ordrer:

  1. curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.33.11/install.sh | bash

  2. command -v nvm

  3. nvm install node

finally confirm that the update was successful

  1. npm -v
fypnlp
  • 1,372
  • 4
  • 18
  • 41
20

Let's do a better solution if all of the mention methods not help you:

You need to install nvm (Node Version Manager)

After that just run:

nvm install 14

list your versions to see is version installed

nvm ls

and you will get list like this:

        v10.2.0
       v12.18.3
->     v14.10.0
         system
default -> 14.10.0 (-> v14.10.0)
node -> stable (-> v14.10.0) (default)
stable -> 14.10 (-> v14.10.0) (default)
iojs -> N/A (default)
unstable -> N/A (default)
lts/* -> lts/erbium (-> v12.18.3)
lts/argon -> v4.9.1 (-> N/A)
lts/boron -> v6.17.1 (-> N/A)
lts/carbon -> v8.17.0 (-> N/A)
lts/dubnium -> v10.22.0 (-> N/A)
lts/erbium -> v12.18.3

Switch default version like this:

nvm alias default 14.10.0

And check:

node -v

If print v14.10.0 you are ready to rock, if not:

nvm use 14

and check again.

This need to work like a charm and you will be happy.

Ivijan Stefan Stipić
  • 6,249
  • 6
  • 45
  • 78
  • 1
    This was so helpful and it worked. Thanks – Mo1 Mar 16 '22 at 20:14
  • Tried multiple approaches to install the latest version(s), All got successfully installed, Still the `node -v` call was pointing to the old version 16.X instead of my expectation 18.X. The `nvm use 18` helped me. Thanks a lot :) – Aravinth Jul 01 '23 at 10:39
9

Check your /usr/local/lib folder. I had the same problem and a node_modules folder in here. After removing it and rerunning [sudo] npm install npm@latest -g it showed and used the correct version.

Jannis Hell
  • 736
  • 8
  • 17
6
sudo npm install -g n

If you want latest stable version

sudo n stable

If you want the latest version

sudo n latest

Then restart computer

Ayush Mahajan
  • 639
  • 1
  • 5
  • 14
  • 2
    I tried the command you mentioned and as it did before, it does say that it has updated 1 package and it's now + npm@6.0.0 but when I do a npm -v command, i see that it is still 5.6.0. So I'm quite confused as it always is able to update without errors, but upon checking -v it is still the old verison. – Kelvin Zhao May 03 '18 at 13:22
  • 1
    i had same problem, restart was all I had to do. – Ayush Mahajan May 03 '18 at 15:53
  • 1
    This shouldn't be downvoted... nobody mentioned that you need to restart your computer to get it to apply the changes. +1 – jscul Dec 28 '18 at 00:45
  • Just log out and log in again! – sneaky Oct 08 '19 at 10:24
  • 1
    @jscul restarting, logging out and in, closing and opening terminal, all these didn't work as there was a pathing/aliasing issue that caused this for me. Only a full uninstall of node worked. – Kelvin Zhao Jun 12 '20 at 00:37
2

I had this issue today with Node installer node-v10.16.0-x64.msi. Even after installing it I got the node version from npm -v as 3.10... and my react app would fail to start :(

It seems that node creates a folder in APPDATA at %AppData%\Roaming\npm There was an old npm.exe lying there and this was in my Windows Path at user level. The user level Path overrides the system level Path where the new installer had added its path. The user override caused the new npm to not be found. Solution: Shift-Delete %AppData%\Roaming\npm ! :D Remove and reinstall with node-v10.16.0-x64.msi

Now npm -v gives 6.9.0!

safe_malloc
  • 824
  • 2
  • 12
  • 29
1

If you have tried all the mentioned approach like :- sudo npm install -g n sudo n stable

or

sudo npm install npm@latest -g still npm -v showing you the older version, once try to close your terminal and open a new one and check.

1

Though this is an old question and the answer might not be relevant but I found myself into such situation many time, sometimes restarting the server is not a solution because other process will get effected. So you need to refresh the terminal without actually restarting the server and for that you may run exec bash and that will certainly help.

Khan Shahrukh
  • 6,109
  • 4
  • 33
  • 43
1

I found this command line that worked for me.

Update from version 12.18 to the latest version 15.2 correctly.

I hope this is useful:

nvm install node --reinstall-packages-from=node
Elletlar
  • 3,136
  • 7
  • 32
  • 38
1

I faced a similar issue. I had node v14.15.4 installed on ubuntu 18, but when i used node -v it showed v11.0.0. To check all the node versions available on your system using nvm, use

nvm ls

To set the newly installed node version as the default, use

nvm alias default <version>

Then, just close the terminal and open a new terminal to check the node version.

yksolanki9
  • 429
  • 2
  • 7
  • 14
1

Problem summary

npm -v # 6.xx
npm install npm@latest -g
npm -v # still the same, but should be 7.xx

Solution based on the answer of fypnlp.

curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.33.11/install.sh | bash

The terminal now wants to configure some ~/.zshrc file which I don't have on my Mac yet. So let’s create it

nano ~/.zshrc

and paste

export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"

Now restart the terminal and run

command -v nvm # should return "nvm"
nvm install node
npm -v # now it’s 7.xx yay!
Moritz
  • 249
  • 2
  • 11
0

I think your question is replecated and already has an answer. First, The LTS and current version of NPM is 5.6.0 for both Node 8.11.1 (LTS) and Node 10.0.0 (Latest current version) according to the official documentation.

Otherwise, sudo npm install npm@latest -g should install the latest version NPM globally.

Rafik
  • 395
  • 1
  • 2
  • 12
  • 4
    I've already done sudo npm install npm@latest -g and on my terminal it does say that updated package to +npm6.0.0, but as I mentioned in the initial question when I do a npm -v, I again see that it is 5.6.0. – Kelvin Zhao May 03 '18 at 13:21
0

Search for a node_modules folder in your home directory, rename it or delete it, then try again.

0
  1. First uninstall your installed nodejs from Control Panel\All Control Panel Items\Programs and Features.

  2. Delete nodejs folder from the Program Files (x86) folder.

  3. Now install new version and check it once.

Hoppo
  • 1,130
  • 1
  • 13
  • 32
0

I was facing the same error today.Updated npm version does not reflect.

This is how I resolved it.

  1. A lot of post suggested to use the command npm cache clean --f. But, it did not work for me. Hence, I deleted the "npm" and "npm-cache" folders from the location C:\Users\SearchYourUserName\AppData\Roaming

  2. Uninstalled the existing node.

  3. Re-Installed node version v10.x.x. I downloaded the node-v10.22.1-x64.msi file from https://nodejs.org/dist/latest-v10.x/ and installed it.

Then checked the npm version. It had worked.

0

Actually this could be happening due to mistakes like you installing packages using yarn ex:

// update the version number in package.json then
yarn install

and trying to run scripts using npm like

npm run start

Actually I did this mistake. So make sure to use either yarn or npm, but not both.

user158
  • 12,852
  • 7
  • 62
  • 94
0

I have this same symptom but none of the answers helped and I finally found the issue. It may not be exactly the same as the OP's but I think it is along the same lines. @Kelvin Zhao's solution of un-installing and re-installing worked for him but not for me so this might be useful for others.

My issue ended up being that I use brew and (I can't remember how exactly) but I seem to be have an old version in the brew Celler. Brew didn't know about it, or couldn't tell me as I do a brew uninstall node and it says its doesn't exist. When I run node -v or npm -v I get the old versions.

I uninstalled and reinstalled using brew and npm and sudo npm etc didn't do it. it showed the correct versions being installed but node -v still showed the old.

Turns out there is a version in my /usr/local/Celler directory named node@14.

So running brew uninstall node@14 got rid of that and now node -v doesn't work anymore.

Now re-installing node works. brew install node


More info for further details for those interested.

I wanted to find out where I still had node installed so I did echo $PATH as it had to be somewhere in the path else node -v wouldn't be recognised.

Turns out I had /usr/local/opt/node@14 in my path (which linked to /usr/local/Celler/node@14)

That is how I found it. And now I think I remember how it got there. I'm 90% sure that I did an upgrade of node and brew asked what to do with the old version and I think I said to keep it. And that was my mistake that lead me here (and where I think OP's situation differs)

cigien
  • 57,834
  • 11
  • 73
  • 112
0

In my case, I wanted to use Version 18 and it was showing 16. I'm using homebrew on my mac and the command that worked for me was the following:

brew uninstall node@16

And voila the version that was showing after is 18.

0

I had issue with VS Code when I did nvm alias in its own terminal, even after ran alias command, the version kept switching back to old version even I open a new terminal within the VS Code. But as stupid as it sounds, close and reopen the vscode for me worked, after I set the version in an independent terminal.

ey dee ey em
  • 7,991
  • 14
  • 65
  • 121