2

As you can see in the image below, I see two different versions of node depending on which command I run.

CLI

I need the newer version, but npm sees the old version.

https://cdn.discordapp.com/attachments/485329207518298123/1057604620937080862/image.png

Many times I've removed, purged, reinstalled, etc.

I tried installing nvm as root and setting the node version there, but that didn't help either.

If I use apt install nodejs instead of nvm, it tells me that I already have the newest version, which it believes is 12.22.9.

How do I get npm to recognize the newer version (18.12.1) of node that I installed via nvm?

1 Answer 1

3

It is because you have a different version of the Node.js which is installed for the root and that particular user.

First, you need to uninstall Node.js:

sudo apt-get remove nodejs

or

sudo npm rm npm -g

If you have any problem with the above commands, then after running which node command, go to that directory, and run the following commands:

rm -r bin/node bin/node-waf include/node lib/node lib/pkgconfig/nodejs.pc share/man/man1/node.1

Do the same thing for the current user if needed.

The default Ubuntu/Debian package manager does not have the latest Node.js, and that's why whenever you try to install Node.js with apt install nodejs it says you have the latest version.

According to the official Node.js documentation, for installing the latest version, you should follow these steps:

Using Ubuntu

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

P.S: No need to run npm or node with sudo. Therefore, I highly recommend you to not use every command with sudo.

Sign up to request clarification or add additional context in comments.

1 Comment

I found a fix at around the same time you posted, so I can't test your solution. However, it was in the same direction. I used curl (github.com/nodesource/distributions#installation-instructions), not nvm, to get node. Uninstalled the nvm version. Ran into an error an used this fix: github.com/nodesource/distributions/issues/…

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.