windows Git Bash 看不到我的 PATH
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/10681101/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Git Bash doesn't see my PATH
提问by ulu
When I use Git Bash (on Windows), I cannot run any executable without specifying its full path, although it is located in a folder which is in my PATH variable. Looks like bash doesn't recognize it. Why? Can I fix it?
当我使用 Git Bash(在 Windows 上)时,我无法在不指定完整路径的情况下运行任何可执行文件,尽管它位于我的 PATH 变量中的文件夹中。看起来 bash 无法识别它。为什么?我可以修吗?
采纳答案by ulu
Got it. As a Windows user, I'm used to type executable names without extensions. In my case, I wanted to execute a file called cup.bat
. In a Windows shell, typing cup
would be enough. Bash doesn't work this way, it wants the full name. Typing cup.bat
solved the problem. (I wasn't able to run the file though, since apparently bash couldn't understand its contents)
知道了。作为 Windows 用户,我习惯于键入不带扩展名的可执行文件名。就我而言,我想执行一个名为cup.bat
. 在 Windows shell 中,键入cup
就足够了。Bash 不是这样工作的,它需要全名。打字cup.bat
解决了这个问题。(虽然我无法运行该文件,因为显然 bash 无法理解其内容)
One more reason to switch to posh-git..
切换到 posh-git 的另一个原因..
Thanks @Tom for pointing me to the right direction.
感谢@Tom 为我指明了正确的方向。
回答by Tom
Maybe bash doesn't see your Windows path. Type env|grep PATH
in bash to confirm what path itsees.
也许 bash 没有看到您的 Windows 路径。键入env|grep PATH
在bash,以确认哪些路径它看到的。
回答by Mika?l Mayer
Following @Daniel's comment and thanks to @Tom's answer, I found out that Git bash was indeed using the PATH but not the latest paths I recently installed. To work around this problem, I added a file in my home (windows) directory named:
遵循@Daniel 的评论并感谢@Tom 的回答,我发现 Git bash 确实使用了 PATH 而不是我最近安装的最新路径。为了解决这个问题,我在我的 home (windows) 目录中添加了一个名为:
.bashrc
.bashrc
and the content as follow:
内容如下:
PATH=$PATH:/c/Go/bin
PATH=$PATH:/c/Go/bin
because I was installing Go and this path contained the executable go.exe
Now Git bash was able to recognize the command:
因为我正在安装 Go 并且此路径包含可执行文件go.exe
现在 Git bash 能够识别命令:
go
go
Perhaps just a system reboot would have been enough in my case, but I'm happy that this solution work in any case.
也许在我的情况下只需重新启动系统就足够了,但我很高兴这个解决方案在任何情况下都有效。
回答by Smile4ever
Create a file in C:\Users\USERNAME which is called config.bashrc, containing:
在 C:\Users\USERNAME 中创建一个名为 config.bashrc 的文件,其中包含:
PATH=$PATH:/c/Program\ Files\ \(x86\)/Application\ with\ space
Now move the file on the command line to the correct location:
现在将命令行上的文件移动到正确的位置:
mv config.bashrc .bashrc
回答by Muthamizhchelvan. V
While you are installing Git, you can select the option shown below, it'll help you to set the path automatically.
在安装 Git 时,您可以选择如下所示的选项,它会帮助您自动设置路径。
Its worked out for me :)
它对我有用:)
回答by Pavel
Restart the computer after has added new value to PATH.
将新值添加到 PATH 后重新启动计算机。
回答by fernandosavio
Old question but it can help someone else.
老问题,但它可以帮助别人。
I've changed my PATH user wide, after that I've just logoff and login again.
我已经更改了我的 PATH 用户范围,之后我刚刚注销并再次登录。
That is it! git bash
loaded the new PATH value correctly.
这就对了!git bash
正确加载了新的 PATH 值。
回答by romin21
On Windows 10, just uninstall git and install it again. It will set the environment variable automatically for you. I had removed the environment variable by mistake and I couldn't use git inside my IDE. Reinstalling git fixed this issue.
在 Windows 10 上,只需卸载 git 并重新安装即可。它将自动为您设置环境变量。我错误地删除了环境变量,无法在 IDE 中使用 git。重新安装 git 解决了这个问题。
回答by Pramod Alagambhat
I can confirm that restarting the system will make sure that the PATH set in the environment variable in windows is picked up by git and there is no other automatic way.
我可以确认重新启动系统将确保在windows中的环境变量中设置的PATH被git拾取并且没有其他自动方式。
回答by JakobN
It seems the root cause here is Git Bash not able to always parse the variable %USERPROFILE% correctly. Instead of making it relative to C:\Users\\ it gets the value C:\Windows\System 32\systemprofile\ After changing this to a fully qualified address, it Works, and even if I set it back afterwards, Git Bash still has the correct PATH for some reason.
这里的根本原因似乎是 Git Bash 无法始终正确解析变量 %USERPROFILE%。而不是使它相对于 C:\Users\\ 它获得值 C:\Windows\System 32\systemprofile\由于某种原因有正确的路径。