3

I installed Node.js on my Ubuntu machine. I typed node but it didn't work. I typed nodejs and it worked. When I asked for the version, node -v didn't work but nodejs --version worked, it gives me "v0.10.25."

I updated Node from https://davidwalsh.name/upgrade-nodejs by using the commands sudo npm cache clean -f, sudo npm install -g n, and sudo n stable.

Still it's not working. What should I do?

enter image description here

eabates
  • 878
  • 1
  • 8
  • 22
user2200091
  • 64
  • 1
  • 5

4 Answers4

3

I would suggest uninstall previous version and install your desired version from scratch.

To uninstall old version:

Run this command in your terminal:

lsbom -f -l -s -pf /var/db/receipts/org.nodejs.pkg.bom | while read f; do  sudo rm /usr/local/${f}; done

sudo rm -rf /usr/local/lib/node /usr/local/lib/node_modules /var/db/receipts/org.nodejs.*

To install new version:

You can download both LTS and Beta version from the official site of node.js

But the best way would be using NVM. This would help you install and use multiple version of node on a single machine.

You can also use n. Which is similar to NVM but it's lightweight.

Community
  • 1
  • 1
Sk Arif
  • 1,110
  • 6
  • 17
  • lsbom -f -l -s -pf /var/db/receipts/org.nodejs.pkg.bom | while read f; do sudo rm /usr/local/${f}; done IT's showing command not found – user2200091 Nov 06 '16 at 15:15
  • Sorry, I forgot you are running a ubuntu machine. This may help you uninstalling node - http://stackoverflow.com/questions/5650169/uninstall-node-js-using-linux-command-line – Sk Arif Nov 06 '16 at 16:04
  • Not correct. When I run it says lsbom: command not found – MoDzeus May 03 '23 at 10:54
1

try these simple commands:

sudo apt-get purge nodejs
curl -sL https://deb.nodesource.com/setup_12.x | sudo -E bash - 
sudo apt-get install -y nodejs 
  • first you remove the previous nodejs version
  • then download the latest 12.* nodejs version
  • install the new version nodejs

sources: https://vitux.com/how-to-uninstall-programs-from-your-ubuntu-system/ https://github.com/nodesource/distributions/blob/master/README.md#debinstall

Itamar Lev
  • 84
  • 5
1

I ran npm cache clean -f and npm install -g n like you did. After running sudo n stable, I typed in PATH=$PATH as they recommended me to and it worked. Typing node -v verified the update.

0

To update nodejs version in Linux using nvm(you can also use n to update nodejs version)

step 1: use wget to install nvm. Check it's official documentation for the latest version

wget -qO- https://raw.githubusercontent.com/nvm-sh/nvm/v0.35.3/install.sh | bash

Step 2: Check if installation is successful

command -v nvm

Step 3:download and update to the latest Node.js version. This will install the latest version of node. Check nodejs for the recommended versio to install

nvm install node

N.B To Upgrade a different version

nvm install version-number

example: nvm install 14.17.6

restart/close and open the terminal(optional) and check your node version

node -v

source: https://www.whitesourcesoftware.com/free-developer-tools/blog/update-node-js/