I was trying to install nodejs in WSL for Emulating a server enviourment for creating and test a code before deploying into server. I was able to install the node successfully, but had issue with using npm. After a lot searching I was able to fix the issue by using nvm, here I am sharing the step for the same hope it helps.
I had also uninstalled the nodejs before proceding the nvm installation, here are commands for to perform the same:
-
removing nodejs
sudo get-apt remove nodejs
-
update the pakages
sudo apt-get update
-
Install NVM
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.1/install.sh | bash
-
Reload shell
source ~/.bashrc
-
Install the required node version
nvm install v<version number>