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

Npm Install

Npm Install Problem Overview


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

Npm Install Solutions


Solution 1 - Npm Install

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.

Solution 2 - Npm Install

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.

Solution 3 - Npm Install

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

Solution 4 - Npm Install

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

Solution 5 - Npm Install

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

this is enough, if you still face the problem

node installation needs restart, close you ubuntu window and start again it will solve your problem :)

Solution 6 - Npm Install

Linux command for install nodejs and npm

sudo apt-get install nodejs
sudo apt-get install npm

Set path in linux

export PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin

reference https://github.com/microsoft/WSL/issues/3882

Solution 7 - Npm Install

I had the same problem. This is what I did.

Step 1. Type node -v and npm -v commands in Windows PowerShell and check if node and npm are properly installed

Step 2. Add this to the ~/.zshrc or ~/.bashrc file

export NVM_DIR="$([ -z "${XDG_CONFIG_HOME-}" ] && printf %s "${HOME}/.nvm" || printf %s "${XDG_CONFIG_HOME}/nvm")"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"

Step 3. Type source ~/.zshrc and/or source ~/.bashrc

Step 4. Type node -v and npm -v commands in bash or zsh shells and the correct versions should now appear

Solution 8 - Npm Install

On Visual Studio -> Tools -> Options -> Projects and Solutions -> Web Package Management -> make sure $(PATH) is above all the rest.

As long it is not located at the top of the list VS will try to use VS tools instead of npm.

You should also refer windows to the current npm version by following this screenshot, after try npm --version.

Changing npm path:

Solution 9 - Npm Install

I had this issue in both Debian and Ubuntu (though in Ubuntu the nvm command did work) when I was running Windows 10 version 1703. Then when I upgraded to version 1903 the problem disappeared.

Solution 10 - Npm Install

I had the same error and it may seem silly, but I fixed it by simply typing exit in the console and opening it again.

Solution 11 - Npm Install

I received this error when I modified my "~/.bashrc" file to shorten up the bash directory.

At first I had:

if [ "$color_prompt" = yes ]; then
            PS1='${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u\[\033[00m\]:\[\033[01;34m\]\W\[\033[00m\]\$ '
    else
                PS1='${debian_chroot:+($debian_chroot)}\u\h:\W\$'
        fi

....But then could not run any node operation. I rolled it back and the error stopped happening.

After some troubleshooting, I was able to fix the error by adding ~ before the $ on PS1='${debian_chroot:+($debian_chroot)}\u\h:\W\~$

Solution 12 - Npm Install

I just read through many threads trying to do this. There is complete documentation for setting up node, nvm, and npm in wsl, here: https://docs.microsoft.com/en-us/windows/nodejs/setup-on-wsl2

If you already installed node and npm using the following commands,

sudo apt-get install nodejs
sudo apt-get install npm

NPM will not work. You must first uninstall them using:

sudo apt-get remove nodejs
sudo apt-get remove npm

Follow the guide to completely uninstalling here: https://stackoverflow.com/questions/32426601/how-can-i-completely-uninstall-nodejs-npm-and-node-in-ubuntu-14-04

Then reinstall from the windows guide referenced above. The windows guide has many other useful resources.

The Tldr to install(from Microsoft Docs):

sudo apt-get install curl

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

nvm install --lts

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionManu ChadhaView Question on Stackoverflow
Solution 1 - Npm InstallDenis.SabolotniView Answer on Stackoverflow
Solution 2 - Npm InstallcbpView Answer on Stackoverflow
Solution 3 - Npm InstallElton José de SouzaView Answer on Stackoverflow
Solution 4 - Npm InstallGh111View Answer on Stackoverflow
Solution 5 - Npm InstallNikhil SharmaView Answer on Stackoverflow
Solution 6 - Npm InstallAsad ZamanView Answer on Stackoverflow
Solution 7 - Npm InstallZowWebView Answer on Stackoverflow
Solution 8 - Npm InstallOr AssrafView Answer on Stackoverflow
Solution 9 - Npm InstallTheStoryCoderView Answer on Stackoverflow
Solution 10 - Npm InstallDaniel DíazView Answer on Stackoverflow
Solution 11 - Npm InstallReid McCullochView Answer on Stackoverflow
Solution 12 - Npm InstallKeith MosierView Answer on Stackoverflow