3

I am using Bash on Ubuntu on Windows, and I installed git. How do I add git to my PATH?

Vincent
  • 5,422
  • 9
  • 31
  • 55

2 Answers2

7

The General command is (using setx):

setx PATH=%PATH%;C:\path\to\Git\bin

On WSL (Windows Subsytem for Linux), you would type, after installation:

which git

It should be already in your PATH (/usr/bin or /usr/local/bin)

If it is not, you can try and find it: find / -name "git", and add it to your ~/.profile with:

export PATH=$PATH:/path/to/git

But be aware the WSL will install an old version of Git.

Fir the most recent one, use:

sudo add-apt-repository ppa:git-core/ppa
sudo apt-get update
sudo apt-get install git-core

Where is /usr/local/bin on Windows?

As mentioned in BashOnWindows issue 402:

Under C:\Users\**user**\AppData\Local\lxss, You will find:

  • root folder
  • home folder
  • and a hidden rootfs folder (\bin, \boot, \dev, \etc...)

DON'T CHANGE ANYTHINK INSIDE! SERIOUSLY!

Access Windows files via /mnt/**letter**/

And:

Maybe I don't fully understand what Bash on Ubuntu on Windows is.

See Wikipedia WSL entry:

Windows Subsystem for Linux (WSL) is a compatibility layer for running Linux binary executables (in ELF format) natively on Windows 10.
Windows Subsystem for Linux is only available on 64-bit editions of Windows 105 and can be activated on Windows 10 Anniversary Update and later.
WSL uses fewer resources than a full virtualized machine, the most direct way to run Linux software on a Windows computer, while also allowing users to use Windows apps and Linux tools on the same set of files.5

The OP adds:

So if I install git and it's in /usr/bin/git, does that correspond to a particular folder such as C:\Program Files\etc...?

Yes, under C:\Users\**user**\AppData\Local\lxss\rootfs\usr\..., but you are not supposed to access it directly. You only use it through the WSL bash.

Is setting my PATH different by putting it in my ~/.profile vs. going into Control Panel --> System Properties --> Environment Variables

Yes, completely. If you want to set your Windows Environment Variables PATH, you need to use Git for Windows, as described in here.

VonC
  • 1,042,979
  • 435
  • 3,649
  • 4,283
  • How do I figure out the path to git? I can't seem to find it. I installed it originally by running `sudo apt-get install git` – Vincent Jul 04 '17 at 04:45
  • @Vincent You mentions Windows. Windows does not use apt-get. A simple zip, as I describe in the answer, is enough. – VonC Jul 04 '17 at 04:46
  • Sorry, I am on a windows machine, but I'm using Bash on Ubuntu on Windows, so I installed git through the bash shell. – Vincent Jul 04 '17 at 04:50
  • @Vincent OK. I have rewritten the answer accordingly. – VonC Jul 04 '17 at 04:56
  • Hmm.. I'm still a bit confused. Where is /usr/local/bin on Windows? Sorry if that's a dumb question, maybe I don't fully understand what Bash on Ubuntu on Windows is. So if I install git and it's in /usr/bin/git, does that correspond to a particular folder such as C:\Program Files\etc...? Is setting my PATH different by putting it in my ~/.profile vs. going into Control Panel --> System Properties --> Environment Variables? – Vincent Jul 04 '17 at 05:59
2

The solution assumes u want to access git inside WSL in your Windows Environment

Check this Out https://github.com/ardevd/gitwrap/releases

This wrapper pipes output from WSL to windows and also works on android studio claimed by the developer

This Wrapper was not developed by me for any issues plz post on the github page