Reputation: 1642
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?
Upvotes: 108
Views: 124971
Reputation: 721
"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:
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 (commands can be copy & paste into git-bash shell all at once):
Step 1: Run these commands to download /etc/pacman.conf and 3 packages: pacman, pacman-mirrors and msys2-keyring. See my Dec 9, 2022 comment below on why you need zstd in .xz format. These packages/versions were tested on both 32 and 64-bit Portable Git 2.38.1:
if [[ "$HOSTTYPE" == "i686" ]]; then
pacman="
pacman-6.0.0-4-i686.pkg.tar.zst
pacman-mirrors-20210703-1-any.pkg.tar.zst
msys2-keyring-1~20210213-2-any.pkg.tar.zst
"
zstd=zstd-1.5.0-1-i686.pkg.tar.xz
else
pacman="
pacman-6.0.1-18-x86_64.pkg.tar.zst
pacman-mirrors-20220205-1-any.pkg.tar.zst
msys2-keyring-1~20220623-1-any.pkg.tar.zst
"
zstd=zstd-1.5.2-1-x86_64.pkg.tar.xz
fi
curl https://raw.githubusercontent.com/msys2/MSYS2-packages/7858ee9c236402adf569ac7cff6beb1f883ab67c/pacman/pacman.conf -o /etc/pacman.conf
for f in $pacman $zstd; do curl -L https://github.com/mcgitty/pacman-for-git/raw/main/$f -o ~/Downloads/$f; done
Step 2: Unpack them at the root then restore pacman with these commands:
cd /
tar x --xz -vf ~/Downloads/$zstd usr
for f in $pacman; do tar x --zstd -vf ~/Downloads/$f usr etc 2>/dev/nul; done
mkdir -p /var/lib/pacman; ln -s `which gettext` /usr/bin/
pacman-key --init
pacman-key --populate msys2
pacman -Syu
Step 3: The next set of commands restore all matching metadata (be patient). Like the zstd packages in Step 1, this relies on my public github repo pacman-for-git to provide the git-sdk commit ID of each Portable Git release, which I'll do my best to update:
t=`grep -E 'mingw-w64-[ix_0-9]+-git ' /etc/package-versions.txt`
t=`curl -sL https://github.com/mcgitty/pacman-for-git/raw/main/version-tags.txt|grep "$t"`
[[ "$t" == "" ]] && echo "ERROR: Commit ID not logged in github pacman-for-git." && read
b=64 && [[ "$t" == *-i686-* ]] && b=32
URL=https://github.com/git-for-windows/git-sdk-$b/raw/${t##* }
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 mtree; do curl -fsSL "$URL$d/$f" -o $d/$f;
done; [[ ! -f $d/desc ]] && rmdir $d && echo Missing $d; 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!
Upvotes: 28
Reputation: 668
pacman is compressed using zstd now. So updated @michael-chen 's scenario (i use wsl's unzstd):
for f in pacman-6.0.1-25-x86_64.pkg.tar.zst pacman-mirrors-20221016-1-any.pkg.tar.zst msys2-keyring-1~20221024-1-any.pkg.tar.zst; do curl https://repo.msys2.org/msys/x86_64/$f -o ~/Downloads/$f; done
cd /
tar --use-compress-program=unzstd -xvf ~/Downloads/msys2-keyring-1~20221024-1-any.pkg.tar.zst usr
tar --use-compress-program=unzstd -xvf ~/Downloads/pacman-mirrors-20221016-1-any.pkg.tar.zst etc
tar --use-compress-program=unzstd -xvf ~/Downloads/pacman-6.0.1-25-x86_64.pkg.tar.zst usr
mkdir -p /var/lib/pacman
pacman-key --init
pacman-key --populate msys2
pacman -Sy
export 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
Upvotes: 2
Reputation: 15
Copying pacman from msys2 works for me, at the end most people forget that you can use pacman for self update as pacman -Syy msys/pacman
Run in msys pacman -Ql pacman
Copy files listed that match
pacman -Ss pacman
but there are missing files so I run self refresh
pacman -Syy msys/pacman
Upvotes: 1
Reputation: 69
msys2
(Version 20190524 is tested.) or Git for Windows SDK
. (Not fully tested, but it should work.) Both include PacMan and Git.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"
gvfs clone https://dev.azure.com/somebody/_git/somerepo
. Only the gvfs command can not be executed on msys2.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.
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
.C:\Program Files\Git
. By default, it is in C:\msys64
./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.)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.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.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.Upvotes: 6
Reputation: 3900
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 customizedmsys2-runtime
to have a fully working git inside MSYS2.Here the steps to take:
Open an MSYS2 terminal.
Edit
/etc/pacman.conf
and just before[mingw32]
(line #71 on my machine), add thegit-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
- 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
- Then synchronize new repository
pacboy update
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 killpacman.exe
it's still running after the window is closed, because it can linger. Once all are closed, start a new terminal again.Then synchronize again (updating the non-core part of the packages):
pacboy update
- And finally install the Git/cURL packages:
pacboy sync git:x git-doc-html:x git-doc-man:x git-extra: curl:x
- Finally, check that everything went well by doing
git --version
in a MINGW64 shell and it should output something likegit 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:
Upvotes: 14
Reputation: 1330102
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.
Upvotes: 73
Reputation: 694
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)
Upvotes: 50
Reputation: 468
I did not want to move from my already working Git for Windows installation so I improvised a bit:
${git-sdk}/usr/bin/pacman.exe
to ${git}/usr/bin
${git-sdk}/etc/pacman.conf
and ${git-sdk}/etc/pacman.d
to ${git}/etc
${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.
Upvotes: 22