npm commands are not working
My Windows build number is:
Microsoft Windows [Version 10.0.17134.590]
I installed nodejs using this command:
sudo apt install nodejs
When I run node -v I get:
v8.10.0, so apparently, it's properly installed, but when I run npm -v I get:
: 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")
Also FYI, when I run which npm I get:
/mnt/c/Program Files/nodejs/npm, but whne I run which node I get /usr/bin/node
I have node installed on my windows to sometimes use it within Git bash.
What can I do to solve this issue?
Same as #1512 which is Variation #2365 (message) etc. Root cause #1896 ref some insight in #3855 (message).
Thanks for replying. I've skimmed through them, but couldn't really catch a solution & I'm afraid to mess with my current environment. Could you please guide me though one?
$ export PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
$ # ... do node things
That didn't work for me.
$ sudo umount /mnt/c # for good measure
In any event, I don't know the steps you followed to get into the state (starting with installing nodejs on Windows). So I can't give you specific steps to undo the state.
sudo apt install nodejs npm works here with a well-formed $PATH. If you don't have npm installed on Ubuntu then you should have got npm not found. whereis npm should yield /usr/bin/npm. Bonne chance.
whereisnpm yields npm: /mnt/c/Program Files/nodejs/npm /mnt/c/Program Files/nodejs/npm.cmd
Your $PATH still has /mnt/c/Program Files/nodejs (or whereis would not find that path otherwise). Which is why we're setting the path to something sane.

When I run the path command, the whereisnpm yields npm: & when I restart the bash & run whereisnpm again, it's the same as before...
the
whereisnpmyieldsnpm:
Then you don't have npm installed.
$ sudo apt install npm
Which is like sudo apt install nodejs npm above only with one step instead of nodejs and npm separately.
install newest version of nodejs like below
curl -sL https://deb.nodesource.com/setup_12.x | sudo -E bash - sudo apt-get install -y nodejs
then you can use /usr/bin/npm instead of npm
$ export PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin $ # ... do node things
this worked for me
I fixed my npm doing:
$ export PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
$ sudo apt install npm
You need restart visual studio code if you are using embed terminal.
$ export PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin $ # ... do node things
This worked for me. How did this exactly work? Sorry I am just a beginner.
How did this exactly work?
It took all the Windows paths out of $PATH, so you aren't tripping over the node things you've installed on Windows.
There's an alternative.
Install yarn like this:
curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | sudo apt-key add -
echo "deb https://dl.yarnpkg.com/debian/ stable main" | sudo tee /etc/apt/sources.list.d/yarn.list
sudo apt update && sudo apt install yarn
I used Yarn installation documentation of Linux and I have tried and tested it.
Replace && in command with ;; if you are using fish shell.
I had the same issue and was wondering if there is an actual solution for this. Does it make sense to install npm again? I thought the whole point would be to use the existing installation so it doesn't make sense to unmount C, change PATH and do other npm install
Windows node is not same planet Linux node. Nothing is being installed again. The OP didn't have npm installed on their Linux distro (usually Ubuntu) to begin with.
You can summarily ignore the unmount part way above; that was just in response to the "that didn't work for me" message immediately above. [The "didn't work" was just a case of the OP being lost, and unmounting was to guarantee no possibility of Windows node being picked up regardless of what "that didn't work" was supposed to mean.]
The "actual solution" is to ensure you have all the node things installed on WSL, so they get picked up by the Linux node not Windows node. "Things" here means anything executable, notably shell scripts (including #!/usr/bin/env node scripts).
[The suggestion to launder the Windows components out of PATH is for people who have already polluted their paths beyond redemption. Noting that, if you don't give your WSL user permission to pollute the Linux system paths, and you don't give your Windows user permission to pollute C:\Program Files, you won't have a conflict. It just gets folks who are going to play around briefly with node unblocked with a straightforward one-liner.]
$ export PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin $ # ... do node things
exactly what i was looking for! thanks! Added this to my .bashrc and now i can run npm from the Ubuntu LTS from windows
$ export PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin $ # ... do node thingsthis worked for me
This also worked for me
@therealkenc @bterlson
Can Any one tell me how to undo this
$ export PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
$ # ... do node things
Please Anyone tell me how to undo this i tried and how i'm having problems