Git Bash doesn't see my PATH
Asked Answered
A

21

140

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?

Atalya answered 21/5, 2012 at 7:33 Comment(4)
Can you show what exactly is in your PATH variable?Planchette
Hmm how is that related to my question? If you suspect that it is malformed, I'm sure it isn't, since I can run the same executables using the regular Windows shell (cmd).Atalya
@ulu: it is related to your question because the PATH variable is what determines which executables can be found... What does the PATH variable look like from within the Bash shell?Unintentional
Inparticular, it contains /e/Programs/Tools/bin somewhere close to the end, this is the path I'm interested in. Maybe the problem is that I'm trying to run a bat file?Atalya
A
86

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)

One more reason to switch to posh-git..

Thanks @Tom for pointing me to the right direction.

Atalya answered 26/5, 2012 at 6:13 Comment(6)
You can also use an alias in order to shorten the name: alias cup=cup.batUglify
Windows uses both PATH and PATH_EXTENSIONS for resolving executeables, while the Linux world only uses PATHFlemings
Your shell script should definitely not be called anything .bat; the extension implies a Windows batch script - especially on a Windows machine.Mossy
What does posh-git solve? Do you not need to type the extension any more?Polenta
@Polenta posh is a Powershell console, switching to it means a more Windows-friendly console with all familiar commands and shortcuts. And yes, just like on any Windows console, you don't have to type ".exe" or ".bat"Atalya
I been searching why running npm --version in Git Bash keep giving the old version. npm.cmd --version gives the correct version.Infinitive
H
62

Maybe bash doesn't see your Windows path. Type env|grep PATH in bash to confirm what path it sees.

Haile answered 21/5, 2012 at 17:51 Comment(5)
It says: PATH=/c/Users/ulu/bin:.:/usr/local/bin:/mingw/bin:/bin:/e/Programs/Ruby/bin:/c/P rogram Files/Common Files/Microsoft Shared/Windows Live:/c/Program Files (x86)/C ommon Files/Microsoft Shared/Windows Live:/c/Windows/system32:/c/Windows:/c/Wind ows/System32/Wbem:/c/Windows/System32/WindowsPowerShell/v1.0/:/e/Program Files ( x86)/Microsoft SQL Server/90/Tools/binn/Atalya
Try running "which your_batch_file.bat" (without quotes). It should return the location of your batch file, if it really is in the path.Haile
how do i add paths for git-bash to see?Strapless
@AngelS.Moreno update or create a ".bashrc" file under your home directory (e.g. "vim ~/.bashrc" in git bash/cygwin), then add "PATH=$PATH:<your_path_1>:<your_path_2>:...:<your_path_n>" to this file. So, if you wanted "/usr/bin/mypath" to be in the PATH variable, this line would read: PATH=$PATH:/usr/bin/mypathJazminejazz
In my case, rebooting the system was just sufficient, in order to see my new path variables there.Foumart
C
43

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:

.bashrc

and the content as follow:

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

Perhaps just a system reboot would have been enough in my case, but I'm happy that this solution work in any case.

Congelation answered 31/1, 2015 at 18:31 Comment(4)
And to add multiple paths?Pazpaza
PATH=$PATH:/c/Go/bin:/c/other/pathPippa
What do you mean home windows directory? please specify.Spencerspencerian
c:/Users/[myusername]/ that's my home directoryPippa
M
12

While you are installing Git, you can select the option shown below, it'll help you to set the path automatically.

Git installation wizard

Its worked out for me :)

Mohammadmohammed answered 6/12, 2013 at 14:41 Comment(4)
@eranotzap reinstall Git with the alternate option? :)Biffin
@eranotzap Setup the Environemtal Variable else reinstall the GitMohammadmohammed
How does this help get git bash to use the path, when the end result is that git bash won't even be installed?Odiliaodille
@Odiliaodille No, while installing Git Bash it'll ask you for there options as like shown in the screenshot, there you can select any one ask per your need, git bash will get installed with the select option.Mohammadmohammed
A
10

Create a file in C:\Users\USERNAME which is called config.bashrc, containing:

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
Arboretum answered 4/11, 2016 at 7:15 Comment(0)
S
10

Restart the computer after has added new value to PATH.

Shanika answered 25/4, 2017 at 15:38 Comment(4)
The computer doesn't need to be restarted, the terminal session does.Dicho
@Dicho I dont sure, but looks like sometime restart of terminal not helped, but restart of computer helped, so I wrote this answer. Restart terminal is the first, that I try.Shanika
Such a simple answer, and completely effective.Acidhead
@Pavel: Exactly right. Restarting the terminal did not help but a computer restart helped. Maybe a logout would be sufficient... I did not try this out however.Nitrochloroform
M
10

In case your git-bash's PATH presents but not latest and you don't want a reboot but regenerate your PATHs, you can try the following:

  • Close all cmd.exe, powershell.exe, and git-bash.exe and reopen one cmd.exe window from the Start Menu or Desktop context.

  • If you changed system-wide PATH, you may also need to open one privileged cmd window.

  • Open Git bash from Windows Explorer context menu and see if the PATH env is updated. Please note that the terminal in IntelliJ IDEA is probably a login shell or some other kind of magic, so PATH in it may won't change until you restart IDEA.

  • If that does not work, you may need to close all Windows Explorer processes as well and retry the steps above.

    Close all Windows Explorer processes using Task Manager:

    1. Apps - Windows Explorer - right click - End task
    2. scroll down
    3. Windows processes - Windows Explorer - right click - Restart

Note: This doesn't work with all Windows versions, and open cmd.exe anywhere other than the Start Menu or Desktop context menu may not work, tested with my 4 computers and 3 of them works. I didn't figure out why this works, but since the PATH environment variable is generated automatically when I login and logout, I'd not to mess up that variable with variable concatenation.

Misjoinder answered 14/4, 2020 at 2:4 Comment(1)
Closing all windows terminals and git bash resolved this issue.. I tried sourcing bashrc but this actually fixed it.Pelt
R
4

Old question but it can help someone else.

I've changed my PATH user wide, after that I've just logoff and login again.

That is it! git bash loaded the new PATH value correctly.

Rocker answered 25/4, 2018 at 13:39 Comment(2)
Is it possible without closing git bask or logging off. I mean i want to set path variable, and i can use it it current git bashValparaiso
Maybe you could do: export PATH=$NEW_PATH:$PATH. And do stuff normallyRocker
A
2

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.

Accompany answered 26/10, 2017 at 13:14 Comment(1)
restarting the terminal is enough to pick new pathMir
A
2

I know it is an old question but there's two type of environment variables. The one owned with User and the one system wide. Depending how do you open git bash (with user privilege or with administrator privilege) the environment variable PATH used can be from you User variables or from System variables. See below: enter image description here

as said in a previous answer, check with the command env|grep PATH to see which one you are using and update your variable accordingly. BTW, no need to reboot the system. Just close and reopen the git bash

Angellaangelle answered 15/10, 2019 at 10:57 Comment(0)
W
1

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.

Wellrounded answered 14/12, 2016 at 10:1 Comment(0)
O
1

I meet this problem when I try to use mingw to compile the xgboost lib in Win10. Finally I found the solution.

Create a file named as .bashrc in your home directory (usually the C:\Users\username). Then add the path to it. Remember to use quotes if your path contains blank, and remember to use /c/ instead of C:/

For example:

PATH=$PATH:"/c/Program Files/mingw-w64/x86_64-7.2.0-posix-seh-rt_v5-rev1/mingw64/bin"

Oria answered 3/2, 2018 at 11:5 Comment(0)
A
1

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.

Arawn answered 4/6, 2019 at 15:11 Comment(0)
M
0

For me the most convenient was to: 1) Create directory "bin" in the root of C: drive 2) Add "C:/bin;" to PATH in "My Computer -> Properties -> Environemtal Variables"

Milt answered 15/9, 2014 at 22:58 Comment(0)
Z
0

Don't escape (\) special characters when editing/adding to your $PATH variable. For example, an application directory in program files would look like: PATH=$PATH:/c/Program Files (x86)/random/application

Don't do this:
PATH=$PATH:/c/Program\ Files\ \\(x86\\)/random/application/

Hope this helps.

Zales answered 16/8, 2016 at 22:3 Comment(1)
PATH=$PATH:/c/Program Files (x86)/random/application ... this is not correct bash syntax for setting the PATH. This will temporarily add the directory /c/Program to the path, then try to run the program Files with arguments (x86)/random/application. The only thing wrong with your "don't do this" example is that it has doubled backslashes for the brackets, when single backslashes are correct.Odiliaodille
P
0

I've run into a stupid mistake on my part. I had a systems wide and a user variable path set for my golang workspace on my windows 10 machine. When I removed the redundant systems variable pathway and logged off and back on, I was able to call .exe files in bash and call go env with success.

Although OP has been answered this is another problem that could keep bash from seeing your pathways. I just tested bash again with this problem and it does seem to give a conflict of some sort that blocks bash from following either of the paths.

Plotter answered 30/6, 2018 at 19:17 Comment(0)
S
0

In my case It happened while installing heroku cli and git bash, Here is what i did to work.

got to this location

C:\Users\<username here>\AppData\Local

and delete the file in my case heroku folder. So I deleded folder and run cmd. It is working

Solidify answered 14/12, 2019 at 19:48 Comment(0)
G
0

Git bash terminal on windows operating system have capability to read system path / user path and run the apps but it might miss in following cases

  1. App is added to environment variables without closing terminal
  2. MSYS / MinGW is converting your path
  3. App command your trying to use common alias name instead of original way of calling

Use Case - 1 :

Restart terminals should work and use below command to verify your path

env|grep PATH

Use Case - 2 :

let me explain with an example docker won't work directly on the git bash terminal, for such apps MSYS is converting it origin path. for such issues you might need to tell your terminal ignore path conversion using command MSYS_NO_PATHCONV=1 and proceed with your actual execution command, say for example docker --help should be like below

MSYS_NO_PATHCONV=1  MSYS_NO_PATHCONV=1 docker run -dp 3000:3000 -w /app -v "$(pwd):/app" node:12-alpine sh -c "yarn install && yarn run dev"
717d12b9fe5211f0189ccbed0ba056ca242647812627682d0149ede29af472a4 

Use Case - 3 : let me explain with an example az cli, ideally az cli install in windows as az.cmd which is added to system/user path. on windows operating system either powershell or command prompt recognize az.cmd as az but git bash won't understand it - so you have use alias to avoid the confusion say alias az='az.cmd' and then execute az --help will work for you

Gaffney answered 11/5, 2021 at 3:21 Comment(0)
C
-2

For those of you who have tried all the above mentioned methods including Windows system env. variables, .bashrc, .bashprofile, etc. AND can see the correct path in 'echo $PATH' ... I may have a solution for you.

suppress the errors using exec 2> /dev/null

My script runs fine but was throwing 'command not found' or 'No directory found' errors even though, as far as I can tell, the paths were flush. So, if you suppress those errors (might have to also add 'set +e'), than it works properly.

Concomitant answered 2/3, 2018 at 16:26 Comment(1)
This seems to just be ignoring errors and not solving the root cause of the problem.Fistulous
P
-3

Create a User variable named Path and add as value %Path%, from what I noticed Git Bash only sees User Variables and not System Variables. By doing the mentioned procedure you'll expose your System Variable in the User Variables.

Parisi answered 1/4, 2015 at 14:42 Comment(0)
U
-3

In Windows 7 Path Environment Variables I just add at the end of System Variable path

\;C:\Program Files\Git\bin

and it works now!

Utilitarian answered 24/10, 2017 at 0:37 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.