How to get a list of packages from one machine and install in another with Chocolatey?
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
.
Solution 1:
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.
Solution 2:
This was my poor-man's solution to the same problem, i.e. take all the Chocolatey packages on one machine and install them on another, without worrying about specific versions (i.e. I want the latest versions).
- Use the Export button on Chocolately-GUI to save a packages.config file (to a shared network drive).
- Edit that .config file and remove the
version="X.Y.Z"
fields from each<package ... />
line. - On the new machine run
choco install \\mypc\shared\packages.config -y
.
For example, my edited packages.config file looks like this:
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="audacity" />
<package id="autohotkey" />
<package id="autohotkey.install" />
<package id="ccleaner" />
<package id="chocolatey" />
<package id="chocolatey-core.extension" />
<package id="chocolateygui" />
</packages>
PS.: Don't make the same mistake I did: I used a simple regular expression in Notepad++ to delete all the version="1.1.1"
entries and inadvertently removed the same field from the first <?xml ... ?>
line. This breaks the XML file. Be more careful/clever than me!
Solution 3:
Here is how I generated my packages.config:
$packageXml = ''
choco list -lo -r | % { $_ -split '\|' | select -first 1 } | % { $packageXml += "`n`t<package id=""$_"" />" }
Set-Content "<?xml version=`"1.0`" encoding=`"utf-8`"?>`n<packages>$packageXml`n</packages>" -Path .\packages.config
Once you have that, you take that file to the other machine and do:
choco install packages.config
Solution 4:
The export feature has been finally implemented - documentation link 🎉
I do not recommend using any other version besides the official one, BUT, the branch with the export feature is available here.
You can just run build.bat
and use choco.exe
inside the build_output
directory.
Then you can type
choco export -o="'c:\temp\packages.config'" --include-version-numbers --allowunofficial
to create the export file.