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

I installed node for the Ubuntu side too with the command above:

curl -sL | 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.

0 条评论