The problem is that you need nvm
to be automatically sourced upon login, so either add the following line to your ~/.bashrc
or ~/.profile
file.
[[ -s $HOME/.nvm/nvm.sh ]] && . $HOME/.nvm/nvm.sh
Also nvm
doesn't set any version of node automatically so if you just installed nvm
and installed a node version and try to use node
the next time you login, you get an error that command not found: node
unless you use the nvm use versionnumber
command in every terminal session, so Instead I suggest you to set a default alias so that a default version of node is active for every terminal session using the following command
nvm alias default versionnumber
PS: In the above commands version number denotes the version number of nodejs
that you have already installed using nvm
There are a few... unique things about WSL that matter here. First, if you type the name of a .exe
that is in the Windows side, but from WSL, it will work. For example, open a Bash prompt in WSL, type notepad.exe
, and press enter. Notepad will open.
Before you uninstalled OpenJDK 8, you had openjdk-8-jre
installed in WSL and Java 17 installed in Windows. When you called java
from Windows, it was smart enough to add the .exe
, and run the Windows copy of Java. But, when you switched to WSL, when you typed java
, it ran the Linux version. But if you typed (into WSL) java.exe
, it would have launched the Windows version of Java from WSL for the same reason that Notepad worked.
If I wanted to do Java development from WSL, I would uninstall the Windows version of Java completely, install my desired version of Java in WSL (sudo apt update && sudo apt install openjdk-17-jre
), and just do development from in WSL via the WSL Java compiler.
Best Answer
node.exe
is NodeJS from your Windows environment - that's for Windows, not WSL.You need to install NodeJS from the NodeJS repositories inside of WSL in order to use
npm
and Node within WSL. DO NOT rely on the Windows solutions for installing WSL.Microsoft has specific documentation on how to do this, provided you're using WSL2. I would suggest following the Microsoft documentation. (Not copied here because it's a fairly involved process 'cause of making sure you've got WSL2 and such)