npm install error `not foundram Files/nodejs/npm: 3: /mnt/c/Program Files/nodejs/npm:`

I have installed Ubuntu Bash on Windows. I already have nodejs and npm on my windows machine at C:\Program Files\nodejs. In the bash shell in Windows, I am running a script which uses npm install command. The script is giving following error

: not foundram Files/nodejs/npm: 3: /mnt/c/Program Files/nodejs/npm:
: not foundram Files/nodejs/npm: 5: /mnt/c/Program Files/nodejs/npm:
/mnt/c/Program Files/nodejs/npm: 6: /mnt/c/Program Files/nodejs/npm: Syntax error: word unexpected (expecting "in")

Note: Before following the steps below, first try to restart your shell.

You can install Node.js and NPM with your Windows PowerShell as well, so if you've done that it won't work properly for your Subsystem. That means you have to install it twice (Powershell and Subsystem) or decide on one thing.

If the preceding text, has not helped you, this is how to solve the problem:
Remove your current installations

sudo apt-get --purge remove node
("sudo apt autoremove node" if console is asking for it)
sudo apt-get --purge remove nodejs

Install node the right way. This is for version 14 (view current LTS version):

curl -fsSL https://deb.nodesource.com/setup_14.x | sudo -E bash -
sudo apt-get install -y nodejs

Then install build tools so you can install add-ons for npm later

sudo apt-get install -y build-essential

Now you can type in

npm -v
node -v
Same thing: nodejs -v

to check whether Node.js and NPM are installed correctly. If it shows nothing, restart the shell. If it still shows the same error, restart the WSL/ PC or try with sudo npm -v

Here are two links that may also help you.
https://nodejs.org/en/download/package-manager/#debian-and-ubuntu-based-linux-distributions https://github.com/nodesource/distributions/blob/master/README.md#debinstall

Also, take a look at the Node Version Manager (NVM). With it, you can easily switch back and forth between versions.


The solution provided by phucanhapril on May 24, 2017 in this thread worked for me.

To summarise, edit ~/.profile and change your PATH to this:

PATH="$HOME/bin:$HOME/.local/bin:/usr/bin:$PATH"

(By default it does not include /usr/bin)

Then run:

source ~/.profile

I am not quite sure why npm doesn't work properly in the first place, or why /usr/bin isn't in PATH by default, but the solution worked for me.


I had the same problem to solve I installed "NVM" in my Subsystem

Follow these steps and see if it will solve for you:

sudo apt-get update

sudo apt-get install build-essential libssl-dev

curl -sL https://raw.githubusercontent.com/creationix/nvm/v0.31.0/install.sh -o install_nvm.sh

bash install_nvm.sh

source ~/.profile

nvm install 11.13.0

You can try sudo npm install it was a solution in my particular case.