How come npm install doesn't work on git bash

前端 未结 13 1192
天涯浪人
天涯浪人 2020-12-07 19:00

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

相关标签:
13条回答
  • 2020-12-07 19:22

    In git bash type ...

    which npm
    

    This will tell you where npm is installed.

    Now, I'm assuming this will give you nothing since it seems npm is not on your system PATH variable. The PATH variable defines where Windows looks for commands.

    Go into your control panel and click system advanced settings and add the directory containing npm to your path.

    If you dont know where it is then open a normal windows console and type ...

    where npm
    

    This will show you where it is so you can add it to your path.

    Then close your git bash terminal and reopen it and npm should work.

    PS if you want to check the PATH variable inside git bash, make sure the correct npm folder is on the PATH then just type ...

    echo $PATH
    

    PPS Another tip - you can tweak the PATH for git bash only via your .bashrc OR .bash_profile files.

    0 讨论(0)
  • 2020-12-07 19:24

    The default 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

    0 讨论(0)
  • 2020-12-07 19:26

    I know this post is old but this could help someone who installed Node / npm via Visual Studio Installer. I tried every solution I could find online but none works until I did the following:

    • Uninstall Node using Visual Studio Installer.

    • Install it using installer downloaded from the Node.js site. Use default options.

    0 讨论(0)
  • 2020-12-07 19:30

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

    where node

    where npm

    0 讨论(0)
  • 2020-12-07 19:34

    if you have installed node / npm in a drive other than the os drive you will need to node and npm to the path environment variable (windows) right click on this pc go to advanced system settings -> environment variables -> double click on path and add

    Drive:\nodejs\node_modules\npm\bin

    Drive:\nodejs

    click ok and close the opened cli and open it again to check in cli run :

    echo "$PATH"
    
    0 讨论(0)
  • 2020-12-07 19:41

    In our case, the solution was simply to close the Git bash window and re-open it.

    0 讨论(0)
提交回复
热议问题