Skip to content

Instantly share code, notes, and snippets.

@erikvip
Last active April 4, 2024 12:26
Show Gist options
  • Star 23 You must be signed in to star a gist
  • Fork 6 You must be signed in to fork a gist
  • Save erikvip/63b236078d4ff4163fd3 to your computer and use it in GitHub Desktop.
Save erikvip/63b236078d4ff4163fd3 to your computer and use it in GitHub Desktop.
Import/Export Cygwin List of installed packages

Import & Export Cygwin List of installed Packages

If you want to go from 32 to 64 bit Cygwin but keep all the packages[1], you might find yourself in a spot where you would like to export the list of cygwin packages and also be able to install cygwin with all these packages again. I will tell you how. Open your Cygwin shell and enter

cygcheck -c -d | sed -e "1,2d" -e 's/ .*\$//' > packagelist

This will simply dump a list of installed packages. To install Cygwin 64 with these packages selected, download setup-x86_64[2] and execute it with the command line parameters

./setup-x86_64 -P `awk 'NR==1{printf \$1}{printf ",%s", \$1}' packagelist`
@Owned67
Copy link

Owned67 commented Dec 15, 2017

Open cmd with admin privileges with awk binary on same folder (awk 3.0.3) :
setup-x86_64.exe -P awk 'NR==1{printf $1}{printf ",%s", $1}' packagelist``

Doesn't work... setup-x86_64 installer launches normally...

@tkimva
Copy link

tkimva commented Jan 16, 2018

It works great in cygwin console not windows cmd.

@voorth
Copy link

voorth commented Aug 31, 2018

perhaps a bit clearer:
cygcheck -c -d | sed "1,2d" | cut -d' ' -f1 > package list

@RKirchnerNL
Copy link

I finally got this to work but it took me a while to find out - by combining the initial description with tkimva's comment:

  1. Do an export on the machine that already has all packages installed you want on the new machine, using the cygcheck command from the description at the top and creating the file packagelist.
  2. Download the cygwin installer to an install directory on the new machine, copy the file packagelist from the old machine into the same directory.
  3. Do a minimum installation of cygwin on the new machine as a Windows admin, i.e. just run the cygwin setup program, skip the package selection part, and finish the installation.
  4. Open a cygwin console as Windows admin, navigate to the cygwin install directory.
  5. Run the "./setup-x86_64 -P `awk..." command from the description at the top. This will launch the cygwin setup as normal but instead of showing the usual package selection step you will find the list imported from packagelist, which you can confirm and install.

@Grossdm
Copy link

Grossdm commented Feb 28, 2020

perhaps a bit clearer:
cygcheck -c -d | sed "1,2d" | cut -d' ' -f1 > package list

Even sed is unneeded here. Compact and clean:
cygcheck -cd | tail -n+3 | cut -d' ' -f1 > packagelist

@patrikarlos
Copy link

Note, that "-P" expects a comma separated string with packages. If you have a lot of packages, this list can become too large for the terminal. If thats the case, you need to do some heuristic and split the packagelist file into two or more files. Then run the installer on each of these files.

@pedy711
Copy link

pedy711 commented Apr 22, 2021

@patrikarlos's solution worked for me. In my case, the list was too long and I had to split it into multiple files and run the command above one by one.

@aco319sig
Copy link

@RKirchnerNL's explanation worked for me.

@NotNormallyAGitUser
Copy link

NotNormallyAGitUser commented Aug 15, 2023

I am not savvy with awk, so I found tr to work, too. Also, if the package list is short enough, the single comma-separated list of packages can be created on the source computer so destination computer does not need a pre-installed bare-bones Cygwin in order to assemble such a list:

cygcheck -cd | tail -n+3 | cut -d' ' -f1  | tr '\n' ',' | sed -e s=,$== | tee ~/tmp/PackageList.txt
_autorebase,adwaita-icon-theme,adwaita-themes,alternatives,<...snip...>,xwin-xdg-menu,xwinclip,xwininfo,xxd,xz,zip,zlib0,zstd

This needs to be modified into a *.cmd file by prefixing the single-line comma-separated list with .\setup-x86_64.exe -P .

Just be aware that if you copy the file to a *.cmd file before prefixing the line, Windows 10 will "protect" you from running the file (even though you may select Edit from the context menu). You need to open Notepad first, then load the file.

@kasumiru
Copy link

kasumiru commented Nov 17, 2023

cygcheck -c -d | sed -e "1,2d" -e 's/ .*\$//' | awk '{print $1}' | sed -e ':a' -e 'N' -e '$!ba' -e 's/\n/,/g'  > cygwin_list.txt

and after that on another Windows create bat file with:

setup-x86_64.exe -P _autorebase,adwaita-icon-theme,alternatives,archivemail,... etc full last list. 

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment