68

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?

medavox
  • 103
  • 9
carbolymer
  • 1,033
  • 1
  • 9
  • 23
  • WeiHua Liu 's [answer below](https://stackoverflow.com/a/60611888/6309) seems to be more precise and up-to-date than my 2015 answer. – VonC May 16 '20 at 14:43

6 Answers6

53

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.

VonC
  • 1,042,979
  • 435
  • 3,649
  • 4,283
  • 7
    Yes, I don't expect to have full linux experience from the git bash, but It would be nice to install some command line utilities to make working in windows environment less painful. I tried Git for Windows SDK and it seems that this is what I wanted. Thanks for the hint. – carbolymer Sep 24 '15 at 09:00
  • 3
    You can extract the Git for Windows SDK installer manually and edit the "install" script `setup-git-sdk.bat` to limit the packages that are installed (exclude python and the mingw build tools). This keeps installation size down, but still allows you to upgrade existing and install additional packages using pacman. You'll have to copy `git-bash.exe` and `git-cmd.exe` (and others?) from a Git for Windows installation though. – Brecht Machiels Oct 19 '16 at 19:58
  • @BrechtMachiels OK. I will follow your question at http://stackoverflow.com/questions/25019057/how-are-msys-msys2-and-msysgit-related-to-each-other/35099458#comment67552759_35099458 – VonC Oct 20 '16 at 07:03
  • It would be great to have a (supported?) version of Git for Windows which adds just what you need if you already have MSYS2. Does this exist? – MikeBeaton Oct 30 '18 at 10:13
  • @MikeBeaton Not that I know of. I only know of https://github.com/git-for-windows/git/releases – VonC Oct 30 '18 at 17:07
  • BEWARE. 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. Absolutely nauseated with how much I lost. 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. – dhj Mar 11 '21 at 23:48
  • 1
    @dhj Thank you for the feedback: I have included your comment/warning in the answer for more visibility. – VonC Mar 12 '21 at 06:07
31

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)

medavox
  • 103
  • 9
N. Ngo
  • 466
  • 4
  • 6
  • If you download the package file, you would still need pacman to install it correct? Git for windows doesn't include or support pacman ... unless you use the git for windows sdk which includes pacman but doesn't integrate with regular git for windows install. – Mister_Tom Oct 15 '20 at 15:00
14

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.

Chulup
  • 370
  • 3
  • 10
  • This is perfect for just getting the basic utilities. I can confirm this works for getting 'expect'. – joshhemphill Jan 29 '20 at 19:57
  • 1
    I got 2 errors: error: failed to init transaction (unable to lock database) error: could not lock database: Permission denied I tried to install python and rsync – Esteban Nov 25 '20 at 15:45
10

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

  1. 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

  1. Then synchronize new repository

pacboy update

  1. 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.

  2. Then synchronize again (updating the non-core part of the packages):

pacboy update

  1. And finally install the Git/cURL packages:

pacboy sync git:x git-doc-html:x git-doc-man:x git-extra: curl:x

  1. 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).
MikeBeaton
  • 2,077
  • 2
  • 26
  • 36
  • 1
    This answer assumes that one already has an existing and full MSYS2 installation. I, however, assume that the OP has Git for Windows installed. Therefore the instructions above do not apply to the OP's setup. – Daniel K. Jan 24 '20 at 09:18
  • There is no supported or documented way to simply add pacman to GfW, as far as I understand it. You *can* set up a new, different GfW installation which has pacman; so you do go from having GfW to having GfW with pacman as well... but yes, it would certainly replace your existing GfW installation. – MikeBeaton Jan 24 '20 at 22:02
  • @DanielK.: Nonetheless this answer was quite informative in what are the limitations if you do it "the other way around" (+1 from me). – Fizz Jun 16 '20 at 02:06
  • I see that current versions of MSYS2 actually ship a `git` too (installable via pacman) https://packages.msys2.org/base/git. But it's probably subject some (performance?) limitations... I'm guessing related to the GVFS being discussed in WeiHua Liu's answer, alas not very clearly... – Fizz Jun 16 '20 at 02:13
  • This is being discussed in https://github.com/git-for-windows/git/issues/2688: step 4 is incomplete. – VonC Jul 02 '20 at 05:57
7

"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: Go to msys2 to download 3 packages: pacman, pacman-mirrors and msys2-keyring. Click the "File:" link of each package.

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
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; 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!

Michael Chen
  • 350
  • 2
  • 7
  • 1
    Interesting process, thank you for sharing. Upvoted. – VonC Dec 08 '20 at 17:51
  • 1
    waiting for step 3 takes like 5 minutes – Shimon Doodkin Mar 15 '21 at 22:48
  • You can see it going through one package after another, right? That's what matters. – Michael Chen Mar 16 '21 at 23:04
  • Overall this worked for me, there were two things I had to do extra: 1) The linked packages are now compressed using ZSTD which 7zip doesn't support out of the box. I installed the Modern7z codecs, unpacked them and just `tar` without the decompression. 2) I needed a default `/etc/pacman.conf` file to get it all working which I found here: https://raw.githubusercontent.com/msys2/MSYS2-packages/master/pacman/pacman.conf – Andre Steenveld Apr 20 '21 at 14:58
  • When looking at "Step 3" I found the config file in the git-sdk-64 repo which seems a lot more appropiate as it also has two additional repositories for the git tooling. [/etc/pacman.conf](https://github.com/git-for-windows/git-sdk-64/blob/main/etc/pacman.conf) The script looks like it downloads all the meta data for the installed packages (as listed in the repo) and adds the meta data locally. – Andre Steenveld Apr 20 '21 at 18:03
  • to extract the files i used https://peazip.github.io/index.html . To find the locations I wrote in msys bash "cd /" then "start ." then opened(dragged into) a zst file in peazip then selected only folder(s) and extracted (dragged,while clicking alt tab) only the folders (without metadata) to msys location – Shimon Doodkin Apr 26 '21 at 07:20
3

Tested on Windows 10 x86_64 1909 10.0.18363.752

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.

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, neither fully 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 else. 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 folder, overwrite existing files. That 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 a 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 system property of the control panel. Re-login 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.

WeiHua Liu
  • 31
  • 3
  • Upvoted: that seems a better answer than mine (written in 2015) – VonC May 12 '20 at 13:57
  • This would be a more helpful answer if it explained what "VFS for Git for Windows" actually is and also what "Scalar for Git for Windows" is... – Fizz Jun 16 '20 at 02:10
  • @vonC I'm confused -- are you endorsing VFS for Git? WeiHua seems to say very little about MSYS2 or Git For Windows SDK. – Josiah Yoder Sep 01 '20 at 20:04
  • @JosiahYoder I was acknowledging that an *alternative* to Git for Windows SDK/mysgit could be used (here through VFS) could be used to use pacman. VFS did not exist when I originally wrote my answer. – VonC Sep 01 '20 at 20:10