How to uninstall node from WSL?

Viewed 2047

I have installed nodejs using npm on WSL2. The node version is 16.2.0. I browsed StackOverflow on how to delete and upgrade or downgrade node on Windows and Linux but never have any answer on WSL.

Tried:

npm install -g node@10.19.0

An error message of the command says:

File exists: /home/blold/.nvm/versions/node/v16.2.0/bin/node
Remove the existing file and try again,
Use --force option with command to downgrade the node. 
  1. Tried to go to /home/blold/.nvm/versions/node/v16.2.0/bin/node to delete existing files but it says it is not a directory. At least I should delete existing node files but how?

  2. Using --force seems not a good solution for the question.

What should I do?

1 Answers

Feel frustrated to have to answer my own question.

You don't need to downgrade your nodejs for specific project. In above question, I have to downgrade my node from V16.2.0 to V10.19.0 and wanted to delete higher version of nodejs to have lower version active with "npm install -g node@10.19.0" but it doesn't work.

Here's solution.

  1. Create a new project directory using "mkdir NodeTest" and the location of the directory seems to be your default user directory. (works for me)
  2. Go to the directory
  3. Before installing nodejs V10.19.0 try to find out which version of nodejs is installed by typing "nvm ls"
  4. If the version 10.19.0 is not installed, try "nvm install node@10.19.0 to install it.
  5. If installed try "nvm use v10.19.0" to make it usable.
  6. You can switch to higher version later by "nvm use node"

Some more,

  1. To locate nodejs files type "npm root -g"
  2. To uninstall specific version of nodejs use "nvm uninstall v14.17.0"
Related