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

Manu Chadha picture Manu Chadha · Aug 24, 2017 · Viewed 36.3k times · Source

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")

Answer

Denis.Sabolotni picture Denis.Sabolotni · Oct 5, 2017

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

You can install node 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), decide for one thing, or adjust the environment variables.

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)
sudo apt-get --purge remove nodejs

Install node the right way. This is for version 10:

curl -sL https://deb.nodesource.com/setup_10.x | sudo -E bash -
sudo apt-get install -y nodejs
sudo apt install node

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 npm is installed correctly. If it shows nothing, restart the shell.

Here is a link that may help you.
https://nodejs.org/en/download/package-manager/#debian-and-ubuntu-based-linux-distributions