简体   繁体   中英

npm command not found in zsh but found in bash

I installed npm with nvm and the first time it went all great, now I tried to check npm version on Mac terminal an it shows:

% npm --version
zsh: command not found: npm

But using VSCode terminal with bash, with same command, shows:

npm --version
6.14.12

Is there a chance I installed the wrong way npm or nvm ? Or is this a way I can tell Mac terminal to use bash instead of zsh?

I managed to solve this issue first by executing echo $PATH in both bash and zsh the result was:

bash : /Users/myuser/.nvm/versions/node/v12.22.1/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin

zsh : /usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin

Both paths have /usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin

But only bash has this: /Users/myuser/.nvm/versions/node/v12.22.1/bin:

So I needed to add that missing path to zhs path, since I didn't have a .zshrc file I needed to do:

echo 'PATH="~/.nvm/versions/node/v12.22.1/bin:$PATH"' >> ~/.zshrc

After that I do reset on terminal and verify again with echo $PATH that I have the same path on both terminals.

Finally executed the following command: source ~/.zshrc , reseted terminal again and now both bash and zhs are sync and usable.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM