问题
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