Sometimes I found unexpected packages in my Chocolatey package list, and want to know if they're safe to uninstall. I know I can try to uninstall them and wait for Chocolatey to remind me, but that means I have to do this one by one.
3 Answers
The following Powershell "one-liner" will display all dependencies for each package installed on your system
cd C:\ProgramData\chocolatey\lib
Get-ChildItem C:\ProgramData\chocolatey\lib -Recurse -Name "*.nuspec" | % { Select-String "<dependency" $_ }
Or (adapted from the suggestions in the comments):
foreach ($nuspec in (Get-ChildItem C:\ProgramData\chocolatey\lib -Recurse "*.nuspec")) {
$metadata = ([xml](Get-Content $nuspec.Fullname)).package.metadata
foreach ($dependency in $metadata.dependencies.dependency) {
[PSCustomObject] @{
package = $metadata.id
version = $metadata.version
dependson = $dependency.id
dependencyversion = $dependency.version
}
}
}
-
2As it is a XML, this might work better:
$(Get-ChildItem C:\ProgramData\chocolatey\lib -Recurse "*.nuspec" | % {([xml](gc $_.Fullname)).package.metadata.dependencies.dependency } )
– MKZCommented Jan 5, 2021 at 15:52 -
1This only works if you are inside the folder you are querying, so you must first
cd C:\ProgramData\chocolatey\lib
Commented Dec 3, 2021 at 21:07 -
This doesn't tell you which packages are used by each dependency, just a bulk list of dependencies.– pbarneyCommented May 7, 2022 at 13:06
I don't know of an answer to your exact question, as creating such a list would require a much better knowledge than mine of how Chocolatey installs products. I would then rather try to comment on the underlying problem you are facing, which is the reason that you asked this question.
It's possible to uninstall a Chocolatey package and all its dependencies using
the parameter
-x
(--forcedependencies
)
to also uninstall dependencies when uninstalling package(s).
The default behavior is not to uninstall dependencies.
For example :
choco uninstall notepadplusplus atom 7zip -x
With this switch, Chocolatey is supposed to only reduce the dependent count of any one dependency that is shared among several installed packages when one of the packages is uninstalled.
This means that you don't need to know if they have dependencies or not.
If by any bug Chocolatey ever mishandles this feature and uninstalls a dependency while it is still in use by another package, the damage is easily fixed. See the experiments carried out in this Stack Overflow answer.
-
Sorry, I didn't get notification and forgot the question. I try not to abandon my questions in the future. Commented Nov 8, 2018 at 14:14
-
choco uninstall gpg4win
results ingpg4win not uninstalled. An error occurred during uninstall: Unable to find package 'gpg4win'.
for example. Commented Nov 8, 2018 at 14:16 -
Using a standard DOS prompt, this will list the dependencies for each Chocolatey package:
for /r "%ChocolateyInstall%\lib\" %f in (*.nuspec) do @echo %~nxf & @type "%f"|find /i "dependency id" || echo no dependencies
Note: this assumes that Chocolatey is installed.
deborphan
ordebfoster
.KB
* andvcredist
redistributables.-x
(--forcedependencies
) as inchoco uninstall notepadplusplus atom 7zip -x
. This means that you don't need to know if they have dependencies or not.