Win10的Ubuntu子系统运行npm命令报错的解决方案
2017-12-22
I was having this issue when running zsh
with oh-my-zsh
inside the WSL. but changing the PATH
helped.
In my ~/.bashrc
I have this script to automatically go to zsh
when launching bash:
if test -t 1; then
exec zsh
fi
I installed node
for the Ubuntu side too with the command above:
curl -sL https://deb.nodesource.com/setup_6.x | sudo -E bash -
sudo apt-get install -y nodejs
But I was still running into the same error because my which npm
pointed to Program Files, while sudo which npm
pointed usr/bin/npm
. Exporting the correct path was the correct solution, the oh-my-zsh creates a handy configured ~/.zshrc
file, which has this on top:
# If you come from bash you might have to change your $PATH.
# export PATH=$HOME/bin:/usr/local/bin:$PATH
Which I changed to the default Ubuntu one export PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games
and sourced the file with source ~/.zshrc
and everything started working just fine.