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.
-
So you want the Chocolatey equivalent of the Linux `deborphan` or `debfoster`. – unforgettableidSupportsMonica Mar 21 '17 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 Oct 31 '18 at 20:57
-
Some packages on my system which certainly are dependencies: gpg4win, gpg4win-vanilla, sumatrapdf.commandline, Windows `KB`* and `vcredist` redistributables. – user198350 Oct 31 '18 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 Nov 01 '18 at 15:56
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
}
}
}
- 51
- 1
- 4
-
2As it is a XML, this might work better: `$(Get-ChildItem C:\ProgramData\chocolatey\lib -Recurse "*.nuspec" | % {([xml](gc $_.Fullname)).package.metadata.dependencies.dependency } )` – MKZ Jan 05 '21 at 15:52
-
1This only works if you are inside the folder you are querying, so you must first `cd C:\ProgramData\chocolatey\lib` – K Robinson Dec 03 '21 at 21:07
-
This doesn't tell you which packages are used by each dependency, just a bulk list of dependencies. – pbarney May 07 '22 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.
- 455,459
- 31
- 526
- 924
-
Sorry, I didn't get notification and forgot the question. I try not to abandon my questions in the future. – user198350 Nov 08 '18 at 14:14
-
`choco uninstall gpg4win` results in `gpg4win not uninstalled. An error occurred during uninstall: Unable to find package 'gpg4win'.` for example. – user198350 Nov 08 '18 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.
- 687
- 8
- 24