1

Installing nodejs doesn't update nodejs version

$ nodejs --version
v8.10.0
$ sudo npm install -g nodejs@latest
+ nodejs@0.0.0
updated 1 package in 1.558s

$ nodejs --version
v8.10.0

NodeJS path found at

$ which nodejs
/usr/bin/nodejs

How can I update Nodejs version to latest

Muhzin
  • 390
  • 6
  • 19
  • Uninstall the previous version as described here https://stackoverflow.com/a/33947181/3284355 and then follow this to install new version https://github.com/nodesource/distributions#installation-instructions – Molda Mar 17 '20 at 09:22

1 Answers1

0

It's better to use NVM to install any version of nodejs and flexibility to switch between any nodejs version.

Install NVM using (for ubuntu)

sudo apt-get update
sudo apt-get install build-essential libssl-dev

curl -sL https://raw.githubusercontent.com/creationix/nvm/v0.33.8/install.sh -o install_nvm.sh

To check nvm installed & find available nodejs versions

nvm ls-remote 

Install node

nvm install 12.16.1

Now nodejs version should show 12.16.1

node --version   # 12.16.1

More ref can be found here

Dipten
  • 1,031
  • 8
  • 16