Package management in Git for Windows (Git Bash)?

WindowsGitBashMsysgitMsys

Windows Problem Overview


I'm reading the github wiki for git-for-windows and it says that msys2 bundles pacman: https://github.com/git-for-windows/git/wiki/Package-management

But when I invoke it I get:

$ pacman
bash: pacman: command not found

Does anyone have an idea what is going on?

Which git version does this wiki refer to?

Is there a way to install additional packages to msys2 inside Git for windows?

Windows Solutions


Solution 1 - Windows

As mentioned in issue 397:

> This is intended. We do not ship pacman with Git for Windows.
If you are interested in a fully fledged package manager maintained environment you have to give the Git for Windows SDK a try.

The bash that you see in the latest git for Windows (2.5.3), which is a more recent bash than the old msysgit one, is only there to execute git commands.
It is not a full-fledged linux environment to install any third-party package.


Warning: dhj reports in the comments

> Do not link your existing git for windows with the msys2 main system by using a directory junction.
If you uninstall it will decide that linked directory belongs to it and DELETE YOUR ENTIRE HOME DIRECTORY including sub-directories like "Downloads".
Beware dealing with msys2. > > I don't know if the same is true for the git for windows SDK, but BE CAREFUL trying to get pacman from other systems integrated with git for windows.

Solution 2 - Windows

Git for Windows (https://gitforwindows.org/ or https://git-scm.com/downloads) has Git Bash but it does not include tree.

tree is available via pacman (Package Manager), but that is only available if you install "Git for Windows SDK" (scroll to the bottom of https://gitforwindows.org/ which provides a link to download installer for it from https://github.com/git-for-windows/build-extra/releases/latest)

The accepted answer was very helpful. They mention that git-for-windows was not meant to include pacman in the default install.

So I installed "Git for Windows SDK", then in its bash prompt (SDK-64) I ran the following to install current tree v1.7.0-1 (as of this posting Aug 30, 2018):

[SDK-64: Bash Terminal for Git for Windows SDK]
pacman -S tree
...
Proceed with installation? [Y/n] Y

On my system, Git for Windows SDK is installed under: C:\git-sdk-64, so from my Git for Windows Bash shell (which did not have tree installed), I copied it over tree.exe to its /usr/bin directory, e.g.

[MINGW64: Bash Terminal for Git for Windows]
cd /usr/bin
cp /c/git-sdk-64/usr/bin/tree.exe .

Now I can run tree v1.7.0 from both Git Bash shells.

To make it even easier for others and maybe myself on a future machine, I looked at where pacman was getting the tree package from by running the following in my Git for Windows SDK Bash terminal:

$ pacman -S --info tree
Repository      : msys
Name            : tree
Version         : 1.7.0-1
Description     : A directory listing program displaying a depth indented list of files
Architecture    : x86_64
...

The key thing here is that pacman is getting tree from the "msys" repository (FYI: even though it says msys, it really is using msys2), so I looked at /etc/pacman.d/mirrorlist.msys and the first mirror points to http://repo.msys2.org/msys/$arch/

So next time you want a package that is NOT in Git for Windows, you can download them from: http://repo.msys2.org/msys/x86_64/ (for 64-bit) or from http://repo.msys2.org/msys/i686/ (32-bit)

e.g. direct download link for tree v1.7.0-1

FYI: Git SCM's Window's download at https://git-scm.com/download/ pulls the latest from Git for Windows GitHub (https://github.com/git-for-windows/git from the https://github.com/git-for-windows/git/releases/ link)

Solution 3 - Windows

I did not want to move from my already working Git for Windows installation so I improvised a bit:

  1. Install Git for Windows SDK somewhere else. You'll need more than 3 GB of free space for that.
  2. Copy ${git-sdk}/usr/bin/pacman.exe to ${git}/usr/bin
  3. Copy ${git-sdk}/etc/pacman.conf and ${git-sdk}/etc/pacman.d to ${git}/etc
  4. Copy ${git-sdk}/var to ${git}/

That's all. You can now open your Git Bash and run pacman -S python to install packages on your existing Git for Windows setup.

You will need write access to Git for Windows directory. Also, your pacman now thinks it has a lot of packages installed (from SDK) but it did not stop me from using it.

Solution 4 - Windows

"Git for Windows SDK" is 5.33GB compared to "Git for Windows" 691MB compared to "Portable Git" 275MB. I use the lean and mean Portable Git. At first, it seems hopeless trying to restore and use pacman in the latter two flavors of Git (msys2), because Google excluded ALL metadata files in /var/lib/pacman/local. Please read this official explanation:

https://wiki.archlinux.org/index.php/Pacman#.22Failed_to_commit_transaction_.28conflicting_files.29.22_error

Without those metadata files, you don't know the exact collection and version of the msys2 packages Google selected to build a release of those 2 flavors of Git. If you force to install or copy the current version of msys2 packages, you run the risk of version mismatch with git binaries Google built and tested.

Well, that's until I discover this file: /etc/package-versions.txt, the laundry list of matching msys2 packages and versions. Now there is a definitive source in github. Here is how I restore pacman in Portable Git:

Step 1: Run these commands to download /etc/pacman.conf and 3 packages: pacman, pacman-mirrors and msys2-keyring. These are .xz packages before msys2 switched to zstd. See my comment below.

curl https://raw.githubusercontent.com/msys2/MSYS2-packages/7858ee9c236402adf569ac7cff6beb1f883ab67c/pacman/pacman.conf -o /etc/pacman.conf
for f in pacman-5.2.2-4-x86_64 pacman-mirrors-20201028-1-any msys2-keyring-1~20201002-1-any; 
 do curl https://repo.msys2.org/msys/x86_64/$f.pkg.tar.xz -o ~/Downloads/$f.pkg.tar.xz;
done

Step 2: Unpack them at the root then restore pacman with these commands:

cd /
tar x --xz -vf ~/Downloads/msys2-keyring-1~20201002-1-any.pkg.tar.xz usr
tar x --xz -vf ~/Downloads/pacman-mirrors-20201028-1-any.pkg.tar.xz etc
tar x --xz -vf ~/Downloads/pacman-5.2.2-4-x86_64.pkg.tar.xz usr
mkdir -p /var/lib/pacman
pacman-key --init
pacman-key --populate msys2
pacman -Syu

Step 3: The next two commands restore all matching metadata. The second command is multi-line but still safe to cut and paste (be patient):

URL=https://github.com/git-for-windows/git-sdk-64/raw/main
cat /etc/package-versions.txt | while read p v; do d=/var/lib/pacman/local/$p-$v;
 mkdir -p $d; echo $d; for f in desc files install mtree; do curl -sSL "$URL$d/$f" -o $d/$f;
 done; done

Step 4: Now, is it too much to ask for 'make' and 'zip'?

pacman -S make zip

Voilà, still just a 337MB mean little environment that can expand and upgrade!

Solution 5 - Windows

There seems to be a documented way to do this without having to install the Git for Windows SDK (which is very large). I was given the link to this info by PhilipOakley when I asked about all this on GitHub issue #1912.

Here's the current text of the Git for Windows GitHub wiki page about it:

>##Install inside MSYS2 proper > >###Please note that this scenario is not officially supported by Git for Windows > > (The reason this is unsupported is that there are no volunteers to support that scenario.) > >This guide assumes that you want the 64-bit version of Git for Windows. > >Git for Windows being based on MSYS2, it's possible to install the git package into an existing MSYS2 installation. That means that if you are already using MSYS2 on your computer, you can use Git for Windows without running the full installer or using the portable version. > >Note however that there are some caveats for going this way. Git for Windows created some patches for msys2-runtime that have not been sent upstream. (This had been planned, but it was determined in issue #284 that it would probably not be happening.) This means that you have to install Git for Windows customized msys2-runtime to have a fully working git inside MSYS2. > >Here the steps to take: > >1. Open an MSYS2 terminal. > >2. Edit /etc/pacman.conf and just before [mingw32] (line #71 on my machine), add the git-for-windows packages repository: > >[git-for-windows] Server = https://wingit.blob.core.windows.net/x86-64 > >and optionally also the MINGW-only repository for the opposite architecture (i.e. MINGW32 for 64-bit SDK): > >[git-for-windows-mingw32] Server = https://wingit.blob.core.windows.net/i686 > >3. Authorize signing key (this step may have to be repeated occasionally until https://github.com/msys2/msys2/issues/62 is fixed) > >curl -L https://raw.githubusercontent.com/git-for-windows/build-extra/master/git-for-windows-keyring/git-for-windows.gpg | pacman-key --add - && pacman-key --lsign-key 1A9F3986 > >4. Then synchronize new repository > >pacboy update > >5. This updates msys2-runtime and therefore will ask you to close the window (not just exit the pacman process). Don't panic, simply close all currently open MSYS2 shells and MSYS2 programs. Double-check Task Manager and kill pacman.exe it's still running after the window is closed, because it can linger. Once all are closed, start a new terminal again. > >6. Then synchronize again (updating the non-core part of the packages): > >pacboy update > >7. And finally install the Git/cURL packages: > >pacboy sync git:x git-doc-html:x git-doc-man:x git-extra: curl:x > >8. Finally, check that everything went well by doing git --version in a MINGW64 shell and it should output something like git version 2.14.1.windows.1 (or newer).

@VonC pointed out in the comments that there is discussion about possible additional steps needed in this approach, around half-way down the discussion at https://github.com/git-for-windows/git/issues/2688.

And now, potentially a new way to achieve the required result too:

Solution 6 - Windows

Tested on msys2 20190524 on Windows 10 x86_64 1909 10.0.18363.752 and msys2 20220128 on Windows 11 x86_64 21H2 10.0.22000.434
Using regular Git for Windows.
  1. Install msys2 (Version 20190524 is tested.) or Git for Windows SDK. (Not fully tested, but it should work.) Both include PacMan and Git.
Using VFS for Git for Windows or Scalar for Git for Windows (Aka Microsoft git). Method #1 (with some limitations)
  1. Install VFSForGit ( https://github.com/microsoft/VFSForGit ).
  2. Install Microsoft git ( https://github.com/microsoft/git ) with this option "Git from the command line and also from 3rd-party software" enabled.
  3. Create a symbolic link named "git" in msys64\usr\bin\ pointing to C:\Program Files\Git\bin\git.exe . Execute the following command in cmd.exe, not in bash. mklink git "C:\Program Files\Git\bin\git.exe"
  4. Clone a new gvfs repo. gvfs clone https://dev.azure.com/somebody/_git/somerepo. Only the gvfs command can not be executed on msys2.
  5. Use the git command as you are on msys2 normally.
Using VFS for Git for Windows or Scalar for Git for Windows. Method #2

Virtual Filesystem for Git (formerly was GVFS. Official website https://vfsforgit.org/ ) is recommended. Version 2.22 & 2.26 are tested. Scalar (Official website https://github.com/microsoft/scalar ) is NOT recommended, nor completely tested.

  1. Install GVFS and Git for Windows with GVFS patch. Or install Scalar for Git and Git for Windows with Scalar patch. NOT BOTH on the same machine. The default installation destination is C:\Program Files\Git.
  2. Install msys2 x64 somewhere other than C:\Program Files\Git. By default, it is in C:\msys64.
  3. Copy files and subfolders of msys2 (except /etc and git binaries. The msys2 comes without git from factory.) to Git for Windows VFS edition, and copy /etc/pacman.d and /etc/pacman.conf in msys64 folder to Git installation folder, overwrite existing files. It will update msys2 and MinGW runtime to the latest version. For PacMan, the necessary files are /usr/bin/pac* ; /etc/pacman.conf ; /etc/pacman.d/ ; /var ; /usr/bin/msys* ; .(Not fully tested.)
  4. Setup terminal applications. Run C:\Program Files\Git\bin\bash.exe will launch the bash of Git for Windows. Run C:\Program Files\Git\usr\bin\bash.exe will launch bash of msys2. Configure the path of bash for terminal programs, such as Hyper Terminal. Since Git is in the system folder, terminal programs should be Run as administrator.
  5. Config $PATH the environmental variable for GVFS. Run this command in Git Bash. export PATH=$PATH:/C/Program\ Files/GVFS or export PATH=$PATH:"/C/Program Files/GVFS". Or set environmental variables for GVFS in the system property of the control panel. Relogin to take effect. Sometimes this configuration does not work, but PacMan can still run.
  6. Fix PacMan. Set executable permission for binaries. Fox example. chmod +x /usr/bin/pacman ; pacman-key --init ; pacman-key --populate msys2 ; pacman-key --refresh-keys ; pacman --sync pacman --refresh --sysupgrade --sysupgrade --overwrite "*" . Use the option --overwrite \* because some packages were installed by Git for Windows instead of PacMan.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestioncarbolymerView Question on Stackoverflow
Solution 1 - WindowsVonCView Answer on Stackoverflow
Solution 2 - WindowsN. NgoView Answer on Stackoverflow
Solution 3 - WindowsChulupView Answer on Stackoverflow
Solution 4 - WindowsMichael ChenView Answer on Stackoverflow
Solution 5 - WindowsMikeBeatonView Answer on Stackoverflow
Solution 6 - WindowsWeiHua LiuView Answer on Stackoverflow