How to add git to PATH (Bash on Windows) - windows

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

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.

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

Related

Is 'Git Bash' classified as a virtual machine?

Is Git Bash classified as a virtual machine?
No, Git-Bash is not an emulator nor a virtual machine (WSL is, AFAIK). It's a port — software, written for Linux (and Unix in general) and compiled to run natively on w32.
In short, no this is not a virtual machine, this is an emulator.
based on this
In Windows, we tend to run commands in CMD but they are actually
executable files that exist in the C:\Windows\System32 folder. The
same case is for bash, it requires the utilities to make the commands
work. In Unix systems, these utilities will be under /usr/bin
directory. So, by installing the Git Bash these utilities will be
installed in C:\Program Files\Git\usr\bin folder.
This program actually installs commands that are created for windows runtime and used as in linux.

How to Uninstall Git for Windows SDK?

Git for Windows SDK apparently uses over 5.25GB of disk space and I have no use for developer kit bloat. Now I want to uninstall but I could not find any instructions online or in documentation. On Windows 7 after install there is no uninstall.exe and no uninstall listing in Programs list. Everything seems to be under the directory:
c:\git-sdk-64
So I would just delete that directory.
I don't see any additions to the Windows path that seem to relate to the Git for Windows SDK.
My basic goal is just to use AVRdude and AVR Toolchain for Windows under windows 7 as described in the instructions here:
https://www.pololu.com/docs/0J67/5.5
where I need Msys2 with pacman to install AVRdude, and I would install tree command, and I want to use a Linux command environment on Windows and Linux to develop AVR Programming resources in a cross platform manner. Any advice from experience would be appreciated since I don't want to pollute my Windows 7.
EDIT - Using windows file explorer, right click on sdk folder, properties, size shown is 5.49GB on disk. I don't see any links installed in the Program menu and I doubt there are other files installed anywhere else. So I am just going to delete this whole folder.
When first installed, the console prompt a clonning action from the github repository. Furthermore, the path choose has a .git folder in it where current status and branches can be seen through command line (with git status).
I havent' seen or ask for the code of the executable, as it might link or copy to other paths, but to me it's very probable it just downloads the github repo and compiles some executables (as files are not exactly the same as in the repo).
The only thing to care is the link created to desktop.

The Lxss folder in windows for Bash on Ubuntu on Windows is missing

Problem and Hypothesis
It's a pretty simple problem, I just can't find the Lxss folder in LocalAppData which is suppose to store files from the Bash on Ubuntu on Windows.
I only see one of two possibilities for why this is. Either Windows moved the Lxss folder in an update for Bash on Ubuntu on Windows, or it is an error specific to my system that has caused Windows not to create the Lxss folder. I don't think this is the possibility though because it is a fresh install of windows.
Steps I have tried:
Unhiding files and folders in windows
Shutting down Bash on Ubuntu on Windows and refreshing my LocalAppData
Restarting Windows and checking my LocalAppData
Screenshots of LocalAppData:
I can add more information if needed.
It was actually moved in the latest release to :
C:\Users\%USERNAME%\AppData\Local\Packages\CanonicalGroupLimited.UbuntuonWindows_79rhkp1fndgsc\LocalState\rootfs\
See this blog post from WLS git repo
You have to uncheck "Hide protected operating system files (recommended)" in the folder options window.
The selected solution is old and valid for Ubuntu only.
For Opensuse leap-15.1 users this is different:
C:\Users\"yourusername"\AppData\Local\Packages\46932SUSE.openSUSE-Leap-15-1_022rs5jcyhyac\LocalState\rootfs
The numbers will differ from version to version and may change in the future.
The trick is to look for something related to Linux in C:\Users\"yourusername">\AppData\Local\Packages\"xxxxx"\LocalState\root\fs
where
"yourusername" is your Windows 10 user login
"xxxxx" is a custom name related to the Linux distribution installed
In the latest version of Windows Fall Creator Update, I found it in C:\Users\%USERNAME%\AppData\Local\lxss\

Android Studio Path to Git executable

I'm developing on windows but have installed Bash for Windows (basically a Unix terminal for those who don't know about Windows 10 anniversary update). I installed git through this terminal (sudo apt-get install git) as opposed to downloading it as a Windows application from GitHub.
I'm now trying to integrate Git into Android Studio, and it's asking for a path to the Git executable. Because I didn't download it as a Windows application, there is no .exe, and instead I've tried to give the path C:\Users\Faizan\AppData\Local\lxss\rootfs\usr\bin\git which is where the terminal tells me where Git is when I type type git. I didn't really expect this to work because it's not an .exe but I'm stuck on ideas from here.
How can I make this work without having to download Git for Windows? How do people who develop on Unix systems deal with this path as they don't have an executable file either?
You still have to download Git For Windows.
Try the portable edition: PortableGit-2.10.0-64-bit.7z.exe
It comes with a bash, but even without opening a bash, you sttill have (in a regular Windows CMD session) 200+ Linux commands in <yourGit2.10>\usr\bin.
And of course, it has a git.exe, which is what your Android Studio needs.

How to install and use "make" in Windows?

I'm following the instructions of someone whose repository I cloned to my machine. I want to use the make command as part of setting up the code environment, but I'm using Windows. I searched online, but I could only find a make.exe file, a make-4.1.tar.gz file (I don't know what to do with it next) and instructions for how to download MinGW (for GNU; but after installing it I didn't find any mention of "make").
How do I use make in Windows without a GNU compiler or related packages?
make is a GNU command so the only way you can get it on Windows is installing a Windows version like the one provided by GNUWin32. Anyway, there are several options for getting that:
The most simple choice is using Chocolatey. First you need to install this package manager. Once installed you simlpy need to install make (you may need to run it in an elevated/admin command prompt) :
choco install make
Other recommended option is installing a Windows Subsystem for Linux (WSL/WSL2), so you'll have a Linux distribution of your choice embedded in Windows 10 where you'll be able to install make, gccand all the tools you need to build C programs.
For older Windows versions (MS Windows 2000 / XP / 2003 / Vista / 2008 / 7 with msvcrt.dll) you can use GnuWin32.
An outdated alternative was MinGw, but the project seems to be abandoned so it's better to go for one of the previous choices.
GNU make is available on chocolatey.
Install chocolatey from here.
Then, choco install make.
Now you will be able to use Make on windows.
I've tried using it on MinGW, but it should work on CMD as well.
The accepted answer is a bad idea in general because the manually created make.exe will stick around and can potentially cause unexpected problems. It actually breaks RubyInstaller: https://github.com/oneclick/rubyinstaller2/issues/105
An alternative is installing make via Chocolatey (as pointed out by #Vasantha Ganesh K)
Another alternative is installing MSYS2 from Chocolatey and using make from C:\tools\msys64\usr\bin. If make isn't installed automatically with MSYS2 you need to install it manually via pacman -S make (as pointed out by #Thad Guidry and #Luke).
If you're using Windows 10, it is built into the Linux subsystem feature. Just launch a Bash prompt (press the Windows key, then type bash and choose "Bash on Ubuntu on Windows"), cd to the directory you want to make and type make.
FWIW, the Windows drives are found in /mnt, e.g. C:\ drive is /mnt/c in Bash.
If Bash isn't available from your start menu, here are instructions for turning on that Windows feature (64-bit Windows only):
https://learn.microsoft.com/en-us/windows/wsl/install-win10
Download make.exe from their official site GnuWin32
In the Download session, click
Complete package, except sources.
Follow the installation instructions.
Once finished, add the <installation directory>/bin/ to the PATH variable.
Now you will be able to use make in cmd.
Install Msys2 http://www.msys2.org
Follow installation instructions
Install make with $ pacman -S make gettext base-devel
Add C:\msys64\usr\bin\ to your path
On windows 10 or 11, you can run the command winget install GnuWin32.Make in the command line or powershell to quickly install it. Than you can use the command cmake.
There is no need to install choco anymore.
The chances are that besides GNU make, you'll also need many of the coreutils. Touch, rm, cp, sed, test, tee, echo and the like. The build system might require bash features, if for nothing else, it's popular to create temp file names from the process ID ($$$$). That won't work without bash. You can get everything with the popular POSIX emulators for Windows:
Cygwin (http://www.cygwin.org/) Probably the most popular one and the most compatible with POSIX. Has some difficulties with Windows paths and it's slow.
GNUWin (http://gnuwin32.sourceforge.net/) It was good and fast but now abandoned. No bash provided, but it's possible to use it from other packages.
ezwinports (https://sourceforge.net/projects/ezwinports) My current favorite. Fast and works well. There is no bash provided with it, that can be a problem for some build systems. It's possible to use make from ezwinports and bash from Cygwin or MSYS2 as a workaround.
MSYS 1.19 abandoned. Worked well but featured very old make (3.86 or so)
MSYS2 (https://www.msys2.org/) Works well, second fastest solution after ezwinports. Good quality, package manager (pacman), all tooling available. I'd recommend this one.
MinGW abandoned? There was usually MSYS 1.19 bundled with MinGW packages, that contained an old make.exe. Use mingw32-make.exe from the package, that's more up to date.
Note that you might not be able to select your environment. If the build system was created for Cygwin, it might not work in other environments without modifications (The make language is the same, but escaping, path conversion are working differently, $(realpath) fails on Windows paths, DOS bat files are started as shell scripts and many similar issues). If it's from Linux, you might need to use a real Linux or WSL.
If the compiler is running on Linux, there is no point in installing make for Windows, because you'll have to run both make and the compiler on Linux. In the same way, if the compiler is running on Windows, WSL won't help, because in that environment you can only execute Linux tools, not Windows executables. It's a bit tricky!
I could suggest a step by step approach.
Visit GNUwin
Download the Setup Program
Follow the instructions and install GNUWin. You should pay attention to the directory where your application is being installed. (You will need it later1)
Follow these instructions and add make to your environment variables. As I told you before, now it is time to know where your application was installed.
FYI: The default directory is C:\Program Files (x86)\GnuWin32\.
Now, update the PATH to include the bin directory of the newly installed program.
A typical example of what one might add to the path is: ...;C:\Program Files (x86)\GnuWin32\bin
Another alternative is if you already installed minGW and added the bin folder the to Path environment variable, you can use "mingw32-make" instead of "make".
You can also create a symlink from "make" to "mingw32-make", or copying and changing the name of the file. I would not recommend the options before, they will work until you do changes on the minGW.
I once had the same problem. But I am surprised not to find one particular solution here.
Installation from GnuWin32 or via winget are good and easy options. But I only found make 3.8.1 there. This version lacks the very important option -O, which handles the output correctly when compiling multithreaded.
choco appears to offer make 4.3, currently. So one could expect recent versions there.
But there is also the option of self compiling. And if you have to install make, which is used for compiling, this should be a valid option.
head to https://www.gnu.org/software/make/ and download a version of your liking
unpack the tar.gz files (use 7zip and unpack the file twice to retrieve the actual content)
navigate to the created directory
open command prompt in that directory
run build_w32.bat gcc This will start the compilation with the gcc compiler, which you would need to install in advance. When running build_w32.bat without any option they try to use the MSVC compiler. Sidenote: I found it surprising that gnu does not use gcc as default but MSVC :-)
ignore the warnings created during compilation. The result should still be fine
retrieve your fresh gnumake.exe from the directoy GccRel (when compiled with gcc)
put this file somewhere where you like and rename to make.exe
add the location to the system variable %PATH%
As others have noted: This manual installation might cause conflicts if you have various make versions installed by other programs as well.
You can also install scoop, then run:
scoop install make
One solution that may helpful if you want to use the command line emulator cmder. You can install the package installer chocately. First we install chocately in windows command prompt using the following line:
#"%SystemRoot%\System32\WindowsPowerShell\v1.0\powershell.exe" -NoProfile -InputFormat None -ExecutionPolicy Bypass -Command "iex ((New-Object System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1'))" && SET "PATH=%PATH%;%ALLUSERSPROFILE%\chocolatey\bin"
refreshenv
After chocolatey is installed the choco command can be used to install make. Once installed, you will need add an alias to /cmder/config/user_aliases.cmd. The following line should be added:
make="path_to_chocolatey\chocolatey\bin\make.exe" $*
Make will then operate in the cmder environment.
Install npm
install Node
Install Make
node install make up
node install make
If above commands displays any error then install Chocolatey(choco)
Open cmd and copy and paste the below command (command copied from chocolatey URL)
#"%SystemRoot%\System32\WindowsPowerShell\v1.0\powershell.exe" -NoProfile -InputFormat None -ExecutionPolicy Bypass -Command " [System.Net.ServicePointManager]::SecurityProtocol = 3072; iex ((New-Object System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1'))" && SET "PATH=%PATH%;%ALLUSERSPROFILE%\chocolatey\bin"

Resources