简体   繁体   中英

npm works via command prompt but not git bash

I used node version manager for windows to install NodeJS by executing:

nvm install 16.2.0

npm still wasn't working, so I ran

nvm list available

Which brought me to here: https://nodejs.org/download/release

I copied the files from npm/npm-1.4.9.zip to the v16.2.0 directory and confirmed it was working by opening a command prompt and executing:

npm -v

However, if I open Git BASH and attempt to execute the same command I get the following error message:

bash: npm: command not found

So I followed umpteen Stack Overflow threads on how to resolve this issue. Nearly every one said to restart Git BASH or Visual Studio Code, so I did and it didn't work. I then restarted my computer and it didn't work. So then I tried updating my PATH by executing the following in my command prompt:

npm config get prefix

Then taking that value and adding it to my PATH environment variable. I then shut every thing down, restarted the computer, opened Git BASH and tried running npm -v again, but it still gives me the same error.

I'm at my wits end and don't know why npm works in my command prompt but will not work in git bash.

UPDATE It is worth mentioning that node -v works fine from Git BASH, it is just npm -v

I was able to solve my issue, though I'm unsure if this is a bug with NVM or not.

As of writing this, the current LTS version of NodeJS is 14.17.0. So I executed:

nvm install 14.17.0
nvm use 14.17.0

This not only installed NPM properly, but it also setup the PATH for me.

So for some reason, installing the newest version of NodeJS via NVM did not install NPM but installing the current LTS version did.

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