I encountered the same problem and found the cause and a simple solution.
After installing nvm in bash a few months ago, I recently decided to give zsh and on-my-zsh a try. I followed the instructions and installed zsh and oh-my-zsh. When trying to run node
or npm
I got the errror:
zsh: /mnt/c/Program Files/nodejs/npm: bad interpreter: /bin/sh^M: no such file or directory
My investigations led me to the $PATH
variable. I then compared the output of echo $PATH
in bash and zsh. In bash the path included the nvm directory, in zsh this directory was not added to the path.
The reason for this difference is that nvm adds a snippet to the end of .bashrc
. In zsh .zshrc
is loaded instead and the snippet will not be executed.
The snippet looks like this:
export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm
[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion" # This loads nvm bash_completion
You can just copy these lines from .bashrc
to the end of .zshrc
, restart the shell, and the issue should be fixed if you have the same problem.