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:

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

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:

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 条评论