Home > Mobile >  node and npm Doesn't Exist, But whereis node and which npm Command Works
node and npm Doesn't Exist, But whereis node and which npm Command Works

Time:03-11

I installed the Linux subsystem on my Windows (Ubuntu) machine, and I wanted to run node scripts. But I get an error saying

Command 'node' not found, but can be installed with:sudo apt install nodejs

but I already have node. It works with other shell scripting languages like PowerShell, and Command Prompt. Same for npm.

I've tried using the whereis node and which npm functions, and they work as expected.

CodePudding user response:

I recommend using nvm to install. it's easier to control the node version

run this to install

curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.38.0/install.sh | bash

then install node long term support

 nvm install --lts

if still have the problem run this, check your node version

PATH="/root/.nvm/versions/node/v6.10.0/bin:$PATH"

CodePudding user response:

but I already have node. It works with other shell scripting languages like PowerShell, and Command Prompt. Same for npm.

As mentioned in the comments, this means that you are using the Windows version of node. When you type:

whereis node

What you get back is likely something under /mnt/<drive_letter>/.../node.exe.

Note the .exe, which means that it is a Windows executable. If it's on your Windows path, you can actually run it with:

node.exe

Instead of just node.

However, this is ultimately going to cause problems if you do. See this question for details.

As mentioned in the comments, install the Linux version of Node in WSL. This goes for pretty much any development tool you will use (e.g. Python, Java, etc.) other than VSCode. For VSCode, install the Windows version and use the "Remote - WSL" extension to access WSL.

  • Related