You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Windows11下Git Bash执行flutter命令报错求助

Flutter & npx 在Git Bash中无法运行的解决方案

问题描述

在Windows 11系统中通过Flutter官网下载Flutter,已将flutter/bin添加至用户环境变量PATH:

  • Git Bash中执行where flutter能正常返回路径,但执行flutter命令时报错:

    'where' is not recognized as an internal or external command,
    operable program or batch file.
    Error: Unable to find git in your PATH.

  • where和git单独在Git Bash中执行正常,Flutter在PowerShell中可正常运行;npx命令也存在同样问题:Git Bash中无法运行,PowerShell中正常。

解决方案

1. 让Git Bash加载Windows系统PATH

Git Bash默认可能未完全加载Windows系统环境变量,执行以下命令修复:

echo 'export PATH="$PATH:/c/Windows/system32"' >> ~/.bashrc

关闭并重新打开Git Bash后,再尝试运行flutter或npx。

2. 给Flutter指定Git路径

如果上述方法无效,直接为Flutter配置Git的具体路径:

  1. 在Git Bash中执行where git,获取Git的完整路径(示例:C:\Program Files\Git\bin\git.exe)
  2. 执行配置命令(替换为你的实际Git路径):
flutter config --git-path "C:\Program Files\Git\bin\git.exe"

3. 调整环境变量顺序

打开Windows环境变量设置,确保flutter/bin和Git的bin目录(如C:\Program Files\Git\bin)在系统PATH列表的靠前位置,避免被其他路径覆盖。修改后重启Git Bash测试。

4. 以管理员身份运行Git Bash

右键点击Git Bash图标,选择以管理员身份运行,尝试执行命令,排除权限导致的环境变量加载异常。

内容的提问来源于stack exchange,提问作者Hamza Shueib

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.19 16:31:33