How come npm install doesn't work on git bash

2019-03-17 13:20发布

I have git bash open and I type in npm install and then it returns:

bash: npm command not found

I don't understand, because I have node.js command prompt and when I type in npm -v then it returns 3.7.3. How come it doesn't work in git?

9条回答
做个烂人
2楼-- · 2019-03-17 13:36

you need to add nodejs to your path, along with npm

where node

where npm

查看更多
甜甜的少女心
3楼-- · 2019-03-17 13:38

If you are on Windows, try this: In CMD, go to folder

C:\Program Files or (x86)\nodejs\

Then try the following

C:\Program Files\nodejs>set path=%PATH%;%CD%
C:\Program Files\nodejs>setx path "%PATH%"

It works for me!

查看更多
不美不萌又怎样
4楼-- · 2019-03-17 13:38

The terminal emulator installed by git is named Mintty. To run npm with Mintty, you need to add the path to an environment variable.

Add the following line to your ~\.bash_profile file. If it does not exist, create it.

PATH="/usr/local/share/npm/bin:/usr/local/bin:/usr/local/sbin:~/bin:$PATH"

When Mintty starts up it will read .bash_profile. You should now be able to run npm from Mintty.

These other questions might be helpful also.

https://unix.stackexchange.com/questions/26047/how-to-correctly-add-a-path-to-path https://askubuntu.com/questions/58814/how-do-i-add-environment-variables

查看更多
贼婆χ
5楼-- · 2019-03-17 13:39

I had the same issue and I successed to solve it by changing the git enviornment system variable from C:\Program Files\Git\cmd to C:\Program Files\Git

Hope that will help someone

查看更多
Emotional °昔
6楼-- · 2019-03-17 13:43

I had to add node path to system variable AND reboot. For some reason closing and reopening git bash was not enough

查看更多
7楼-- · 2019-03-17 13:46

Are you on Windows?

If so, can you go to the Git Bash console and run:

echo $PATH

and then check if the node path(e.g. c/Program Files/node ) is there?

If the node path is not there you'll need to add it to the system path variable.

If it's there, can you try to run npm between double quotes?

"npm"
查看更多
登录 后发表回答