How to npm install with git-bash/mingw32 on win7

主宰稳场 提交于 2019-12-11 09:31:31

问题


I am using git-bash/mingw32 on win7. I am trying to install npm:

$ npm install
sh: npm: command not found.

Git-bash is working normally and is installed correctly. How can I make this work?


回答1:


There is a couple of reasons for this behaviour:

1) npm not installed

2) npm not in %PATH%

You can add npm to %PATH% by running cmd (win+r -> cmd) as administrator and execute:

SET PATH=%PATH%;c:\here\is\path\to\npm\dir

After that — try run npm again.




回答2:


while installing node.js when click the set path option. check system environment path.

# echo $PATH

and see if there is npm/node in it. if not, added them to the system environment.

# set PATH=%PATH%;d:/node/;

mostly reinstall node check the right option will fix this, and update dev env btw.




回答3:


Another possible reason (if node was installed by Visual Studio): a missing npm bash script.

There is an npm.cmd bath file in the path:

C:\Program Files (x86)\Microsoft Visual Studio 14.0\Web\External\npm.cmd

But git bash wont run .cmd files. So you need to create a bash script for npm.

Create the following file named npm in your node folder: (C:\Program Files (x86)\Microsoft Visual Studio 14.0\Web\External\)

#!/bin/sh
basedir=`dirname "$0"`

case `uname` in
    *CYGWIN*) basedir=`cygpath -w "$basedir"`;;
esac

if [ -x "$basedir/node" ]; then
  "$basedir/node"  "$basedir/node_modules/npm/bin/npm-cli.js" "$@"
  ret=$?
else 
  node  "$basedir/node_modules/npm/bin/npm-cli.js" "$@"
  ret=$?
fi
exit $ret


来源:https://stackoverflow.com/questions/26319666/how-to-npm-install-with-git-bash-mingw32-on-win7

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!