Package management in Git for Windows (Git Bash)?

63,094

Solution 1

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

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

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

"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

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

@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:

Share:
63,094
carbolymer
Author by

carbolymer

Software developer

Updated on July 05, 2022

Comments

  • carbolymer
    carbolymer almost 2 years

    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?

  • carbolymer
    carbolymer over 8 years
    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.
  • Brecht Machiels
    Brecht Machiels over 7 years
    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.
  • VonC
    VonC over 7 years
    @BrechtMachiels OK. I will follow your question at stackoverflow.com/questions/25019057/…
  • MikeBeaton
    MikeBeaton over 5 years
    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?
  • VonC
    VonC over 5 years
    @MikeBeaton Not that I know of. I only know of github.com/git-for-windows/git/releases
  • Daniel K.
    Daniel K. over 4 years
    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.
  • MikeBeaton
    MikeBeaton over 4 years
    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.
  • joshhemphill
    joshhemphill over 4 years
    This is perfect for just getting the basic utilities. I can confirm this works for getting 'expect'.
  • VonC
    VonC about 4 years
    Upvoted: that seems a better answer than mine (written in 2015)
  • Fizz
    Fizz almost 4 years
    @DanielK.: Nonetheless this answer was quite informative in what are the limitations if you do it "the other way around" (+1 from me).
  • Fizz
    Fizz almost 4 years
    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
    Fizz almost 4 years
    I see that current versions of MSYS2 actually ship a git too (installable via pacman) 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...
  • VonC
    VonC almost 4 years
    This is being discussed in github.com/git-for-windows/git/issues/2688: step 4 is incomplete.
  • Josiah Yoder
    Josiah Yoder over 3 years
    @vonC I'm confused -- are you endorsing VFS for Git? WeiHua seems to say very little about MSYS2 or Git For Windows SDK.
  • VonC
    VonC over 3 years
    @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.
  • Mister_Tom
    Mister_Tom over 3 years
    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.
  • Esteban
    Esteban over 3 years
    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
  • VonC
    VonC over 3 years
    Interesting process, thank you for sharing. Upvoted.
  • dhj
    dhj about 3 years
    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.
  • VonC
    VonC about 3 years
    @dhj Thank you for the feedback: I have included your comment/warning in the answer for more visibility.
  • Shimon Doodkin
    Shimon Doodkin about 3 years
    waiting for step 3 takes like 5 minutes
  • Michael Chen
    Michael Chen about 3 years
    You can see it going through one package after another, right? That's what matters.
  • Andre Steenveld
    Andre Steenveld about 3 years
    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: raw.githubusercontent.com/msys2/MSYS2-packages/master/pacman‌​/…
  • Andre Steenveld
    Andre Steenveld about 3 years
    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 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.
  • Shimon Doodkin
    Shimon Doodkin about 3 years
    to extract the files i used 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
  • Michael Chen
    Michael Chen almost 3 years
    Andre is correct. Msys2 switched to zstd packages in December 2020, which created a chicken and egg problem: Current releases of Portable Git does not include zsdt, which prevents running the tar commands in Step 2. Adding zsdt (egg) needs pacman (chichen) that needs zstd (egg)... Therefore, I modified the 3 links in Step 1 to download the .xz packages. Hopefully, before msys2 removes all .xz pacakge, Portable Git releases would have also included zstd.
  • Alan Jurgensen
    Alan Jurgensen almost 3 years
    This is my favorite answer, because it allows one to stay with the Git package but add pacman allowing other pkg installs. I was getting signer key trust issues. i solved that by instead installing the latest keyring file like thus: msys2-keyring-1_20210213-2-any.pkg.tar.zst
  • Alan Jurgensen
    Alan Jurgensen almost 3 years
    Oh forgot to add, I feel the git bash install is missing these great packages: p7zip curl make rsync zip tmux cal
  • Andre Steenveld
    Andre Steenveld over 2 years
    I keep coming back to this answer 😅. After making pacman aware of all the installed packages listed in /etc/package-versions.txt I occasionally have some issues with packages I've installed outside of pacman (most likely just screwed up). (re)-Installing these with pacman --sync --overwrite '*' does force the installation. Be careful though if you're going to override some dependency it might break other stuff as well. In turn enlarging the hole you shot in the your foot.
  • Robin Dinse
    Robin Dinse over 2 years
    This worked well, except I had to upgrade the database using pacman-db-upgrade before I could run pacman -Syu. However pacman-db-upgrade only ran once I supplied -r /../ as additional argument, not sure why. Without that argument it prepended an additional slash to the root path, i.e. //…. Finally, I had to install pacman -S --overwrite "*" msys2-keyring.
  • Henke
    Henke over 2 years
    I tried it, but it did not work for me. Are the instructions in this answer for the 32-bit Git Bash or for the 64-bit installation? My installer is https://github.com/git-for-windows/git/releases/download/v2.‌​29.2.windows.2/Git-2‌​.29.2.2-32-bit.exe.
  • Henke
    Henke over 2 years
    However, in MSYS2 (64-bit), pacman works fine for me.
  • Michael Chen
    Michael Chen over 2 years
    Yes, you can see from package/folder names in Step 2 and 3, this was tested in 64-bit version. I may test the 32-bit Portable Git in the spirit of lean and mean.
  • Jack Ting
    Jack Ting about 2 years
    Should add a -f flag to command curl -sSL "$URL$d/$f" -o $d/$f x, other it will save a 404 html file as install.