13

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.

4
  • So you want the Chocolatey equivalent of the Linux deborphan or debfoster. Commented Mar 21, 2017 at 21:34
  • I think that the question would be better worded as "Is there a way to list all Chocolatey packages that have/are dependencies?" since there are much more packages that don't have any.
    – user198350
    Commented Oct 31, 2018 at 20:57
  • Some packages on my system which certainly are dependencies: gpg4win, gpg4win-vanilla, sumatrapdf.commandline, Windows KB* and vcredist redistributables.
    – user198350
    Commented Oct 31, 2018 at 21:02
  • It's possible to uninstall a package and all its dependencies using -x (--forcedependencies) as in choco uninstall notepadplusplus atom 7zip -x. This means that you don't need to know if they have dependencies or not.
    – harrymc
    Commented Nov 1, 2018 at 15:56

3 Answers 3

6

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
        }
    }
}
3
  • 2
    As it is a XML, this might work better: $(Get-ChildItem C:\ProgramData\chocolatey\lib -Recurse "*.nuspec" | % {([xml](gc $_.Fullname)).package.metadata.dependencies.dependency } )
    – MKZ
    Commented Jan 5, 2021 at 15:52
  • 1
    This only works if you are inside the folder you are querying, so you must first cd C:\ProgramData\chocolatey\lib
    – K Robinson
    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.
    – pbarney
    Commented May 7, 2022 at 13:06
3
+50

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.

3
  • Sorry, I didn't get notification and forgot the question. I try not to abandon my questions in the future.
    – user198350
    Commented Nov 8, 2018 at 14:14
  • choco uninstall gpg4win results in gpg4win not uninstalled. An error occurred during uninstall: Unable to find package 'gpg4win'. for example.
    – user198350
    Commented Nov 8, 2018 at 14:16
  • This looks weird: Uninstalling a not-installed package?
    – harrymc
    Commented Nov 8, 2018 at 14:20
2

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.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .