How to get a list of packages from one machine and install in another with Chocolatey?

Natan picture Natan · Apr 2, 2017 · Viewed 15.7k times · Source

Calling clist -l gives me a list of packages with versions:

7zip.install 16.04
ccleaner 5.28.6005
ConEmu 17.3.16.0
...

How do I get this list without version information?

My intention is to use this output to call choco install 7zip.install ccleaner ConEmu ... on another machine. An alternative answer could be how to use the output of clist directly into cinst.

Answer

Gary Ewan Park picture Gary Ewan Park · Apr 2, 2017

If you have a look at the help information for the choco install command (you can do this using choco install -h, you will find the following usage:

cinst <pkg|packages.config> [<pkg2> <pkgN>] [<options/switches>]

As you will see, it is possible to pass a packages.config file, which would contain all the packages that you want to install. The format of this packages.config file is very simple and looks like the following:

<?xml version="1.0" encoding="utf-8"?>
<packages>
  <package id="calibre" version="2.81.0" />
  <package id="chocolatey" version="0.10.3" />
  <package id="chocolatey.extension" version="1.9.6" />
  <package id="chocolatey-core.extension" version="1.1.0" />
</packages>

Once you have this file, installing all the packages again on another machine is a simple one line command.

A simple way to generate this packages.config file would be to install ChocolateyGUI (choco install chocolateygui), which includes an option to export the currently installed list of applications.