Git Bash中Phonegap命令找不到问题求助(Windows系统)
Hey Tim, sorry to hear you're stuck with this frustrating issue after reinstalling your tools—let's work through the most common fixes for this problem on Windows:
1. Make sure Git Bash recognizes your npm global package path
Phonegap and Cordova are installed as global npm packages, so Git Bash needs to know where their executable files are stored. Here's how to check and fix this:
- First, run this command in Git Bash to find where npm saves global packages:
On Windows, this usually returns a path likenpm config get prefixC:\Users\YourUsername\AppData\Roaming\npm(Git Bash will display this as/c/Users/YourUsername/AppData/Roaming/npm). - Next, check if this path is included in your Git Bash system PATH:
echo $PATH - If you don't see the npm prefix path in the output, add it temporarily to test:
Try running# Replace the path below with your actual npm prefix path export PATH="$PATH:/c/Users/YourUsername/AppData/Roaming/npm"phonegap --versionnow—if it works, make this change permanent by adding the sameexport PATHline to your Git Bash profile:- Open (or create) the
.bashrcor.bash_profilefile in your user directory with a text editor:code ~/.bashrc - Paste the
export PATHline into the file, save it, then restart Git Bash.
- Open (or create) the
2. Confirm Phonegap is properly installed globally
Sometimes reinstalls don't complete as expected. Test if the command works outside Git Bash first:
- Open Command Prompt or PowerShell (not Git Bash) and run:
phonegap --version - If this also fails, reinstall Phonegap globally (use admin privileges if needed):
Repeat the same step for Cordova if you need it:npm install -g phonegapnpm install -g cordova
3. Check for admin-installed Node.js path issues
If you installed Node.js with admin rights, your global npm packages might be stored in C:\Program Files\nodejs instead of your user directory. Add this path to Git Bash's PATH too:
export PATH="$PATH:/c/Program Files/nodejs"
(Note: If your path has spaces, wrap it in quotes: export PATH="$PATH:\"/c/Program Files/nodejs\"")
4. Clean npm cache and do a fresh reinstall
Corrupted cache can cause installation glitches. Run these commands in Command Prompt (as admin if required):
npm cache clean --force npm uninstall -g phonegap npm install -g phonegap
Hopefully one of these steps gets your Phonegap commands working in Git Bash again!
内容的提问来源于stack exchange,提问作者Temujin

