Scheduled Maintenance: We are aware of an issue with Google, AOL, and Yahoo services as email providers which are blocking new registrations. We are trying to fix the issue and we have several internal and external support tickets in process to resolve the issue. Please see: viewtopic.php?t=158230

 

 

 

Remove automatically installed dependency cycles

If none of the specific sub-forums seem right for your thread, ask here.
Post Reply
Message
Author
mnalli
Posts: 18
Joined: 2021-07-28 14:50

Remove automatically installed dependency cycles

#1 Post by mnalli »

Hello there,

It's been a few days that I'm scratching my head over a problem: how to automatically remove (automatically installed) packages that are part of a dependency cycle. apt autoremove is not able to do that: it is only able to remove packages when there are no cycles involved, i.e. when the subgraph of dependencies is actually a tree.

It does not happen very often to have such a necessity, but it happens sometimes to install cycles of dependencies when installing packages with lots of dependencies (e.g. metapackages).

For example, if we want to try out different desktop environments we may want to install the correspondent metapackages. The problem is that, when we remove the metapackage, only the packages that are removed by apt autoremove are the one that are orphaned, and in a cycle no package is actually orphan.

A concrete example is that when we install the metapackage lxqt-core the packages lxqt-session and lxqt-qtplugin are installed (between many). The first one depends on the second, while the second recommends the first (recommendation are automatically installed on my system).

Does anyone have some ideas on what is the proper way to handle this kind of situations?
It would be nice to have a program or script that would look for automatic cycles between the dependency subtree of a package and would be able to remove them as well. Something like apt-complete-remove lxqt-core.

I tried to look up some information on this, but it seems nobody really asked anything similar, which is quite weird to me.
Am I missing something?

User avatar
Hallvor
Global Moderator
Global Moderator
Posts: 2029
Joined: 2009-04-16 18:35
Location: Kristiansand, Norway
Has thanked: 139 times
Been thanked: 206 times

Re: Remove automatically installed dependency cycles

#2 Post by Hallvor »

I think the best way to test different desktop environments is by using

Code: Select all

# tasksel
Then just remove it with the same command.
[HowTo] Install and configure Debian bookworm
Debian 12 | KDE Plasma | ThinkPad T440s | 4 × Intel® Core™ i7-4600U CPU @ 2.10GHz | 12 GiB RAM | Mesa Intel® HD Graphics 4400 | 1 TB SSD

mnalli
Posts: 18
Joined: 2021-07-28 14:50

Re: Remove automatically installed dependency cycles

#3 Post by mnalli »

Hallvor wrote: 2021-07-29 09:39 I think the best way to test different desktop environments is by using

Code: Select all

# tasksel
Then just remove it with the same command.
I didn't know of this method, thank you. Anyway, I don't think this solves the problem. I installed MATE with tasksel and then I removed it (again with tasksel).

What the installation does is simply installing the package task-mate-desktop (and its dependencies). What the removing does is simply uninstalling the same package and run autoremove. As a results, cycles are not removed. For example the cycle mate-desktop, mate-desktop-environment, mate-desktop-environment-core is not removed and I had to remove it manually. Also I had to remove manually (Synaptic) a great number of other packages that were not automatically removed, which is not a guarantee that I have removed all of them.

What I am looking for is a way to do this automatically, so that I just have to run apt-complete-remove task-mate-desktop to remove task-mate-desktop, the packages that would be removed by autoremove and the cycles.

User avatar
sunrat
Administrator
Administrator
Posts: 6412
Joined: 2006-08-29 09:12
Location: Melbourne, Australia
Has thanked: 116 times
Been thanked: 461 times

Re: Remove automatically installed dependency cycles

#4 Post by sunrat »

I wasn't sure what you meant by cycles in your first post, but it seems you mean dependencies.
If you install a metapackage it will install a collection of dependencies. When you remove it, the dependencies don't get removed. So say you want to remove just one package dependency, first remove the metapackage and then the dependency. Of course that dependency may also have dependencies so you need to deal with that.
I don't know of a way to automatically remove all dependencies of a metapackage. Maybe someone else does. Meanwhile you can generate a list of dependencies for a metapackage and remove all of them together.

Code: Select all

apt depends <name-of-package>
Or if you wish to regularly install metapackages and remove them, on install apt will show a list of dependencies proposed to install. Copy that list to a text file so you can later remove them.
A simple search reveals an 8 year old thread about the same thing:
viewtopic.php?t=103761
and also and 8 year old StackExchange question with what appears to be a perfect solution:
https://unix.stackexchange.com/question ... -in-debian
I didn't test it though.
“ computer users can be divided into 2 categories:
Those who have lost data
...and those who have not lost data YET ”
Remember to BACKUP!

mnalli
Posts: 18
Joined: 2021-07-28 14:50

Re: Remove automatically installed dependency cycles

#5 Post by mnalli »

Thanks for your reply and for the links. Yeah, maybe the only way to do it is the manual one, but this seems weird to me. It should be relatively easy to write a program that detect dependencies cycles between the dependencies of a package.

The best solution so far seems to be the one of finding the installed packages in /var/log/apt/history.log and remove them manually. This is useful, but is not a general solution I would say: if after some time we install another package that depends on some of the package removed previously, removing manually all the packages installed by the metapackage would result in the removal of the new package as well.

As automatically installed dependency cycles i mean something like the 3 packages mate-desktop, mate-desktop-environment and mate-desktop-environment-core. They are all automatically installed (as part of the dependency subgraph of task-mate-desktop), but the first suggests the second, the second depends on the third and the third depends on the first. As there is a cycle, autoremove is not able to understand when these packages are actually unused (because none of them appears to be orphan).

It would be nice to have a program that removes:
- the (meta)package
- its dependencies that are not required by other packages external to the subgraph

This, at least in theory, should be easy to implement as visit on the subgraph of dependencies of the root package.

I think I will try to implement it, I'm just surprised that there seems not to be a program that can do it already. Maybe there are some problems that I can't see now.

CwF
Global Moderator
Global Moderator
Posts: 2636
Joined: 2018-06-20 15:16
Location: Colorado
Has thanked: 41 times
Been thanked: 192 times

Re: Remove automatically installed dependency cycles

#6 Post by CwF »

mnalli wrote: 2021-07-29 17:36 It would be nice to have a program that removes:
- the (meta)package
There is, synaptic.
Click to remove the meta package in question. Go to the 'marked changes' and re-select the status to install all the things you'd like to keep. It will arrange the dependencies as you go.

User avatar
4D696B65
Site admin
Site admin
Posts: 2696
Joined: 2009-06-28 06:09
Been thanked: 85 times

Re: Remove automatically installed dependency cycles

#7 Post by 4D696B65 »

deborphan
program that can find unused packages, e.g. libraries

deborphan finds "orphaned" packages on your system. It determines which packages have no other packages depending on their installation and shows you a list of these packages. It is most useful when finding libraries, but it can be used on packages in all sections.

This package also includes orphaner, a text menu frontend to deborphan. Please install the recommended packages dialog, gettext-base and apt when you want a working and fully featured orphaner.
https://packages.debian.org/bullseye/deborphan

CwF
Global Moderator
Global Moderator
Posts: 2636
Joined: 2018-06-20 15:16
Location: Colorado
Has thanked: 41 times
Been thanked: 192 times

Re: Remove automatically installed dependency cycles

#8 Post by CwF »

4D696B65 wrote: 2021-07-29 18:14deborphan
Again, synaptic.
It has no default way, but you can make a custom filter to find list orphans. the deborphan package is then not required.

mnalli
Posts: 18
Joined: 2021-07-28 14:50

Re: Remove automatically installed dependency cycles

#9 Post by mnalli »

4D696B65 wrote: 2021-07-29 18:14 deborphan
program that can find unused packages, e.g. libraries

deborphan finds "orphaned" packages on your system. It determines which packages have no other packages depending on their installation and shows you a list of these packages. It is most useful when finding libraries, but it can be used on packages in all sections.

This package also includes orphaner, a text menu frontend to deborphan. Please install the recommended packages dialog, gettext-base and apt when you want a working and fully featured orphaner.
https://packages.debian.org/bullseye/deborphan
Hmm... as far as I know deborphan is mainly used to hunt packages that are orphan, but are manually installed (mainly libraries that are not in use). In this case I don't think it could really be useful because in a dependency cycle no package is really orphan.

mnalli
Posts: 18
Joined: 2021-07-28 14:50

Re: Remove automatically installed dependency cycles

#10 Post by mnalli »

CwF wrote: 2021-07-29 18:26
4D696B65 wrote: 2021-07-29 18:14deborphan
Again, synaptic.
It has no default way, but you can make a custom filter to find list orphans. the deborphan package is then not required.
I don't understand exactly what you mean. For example in the example that I did before (the cycle of mate-desktop, mate-desktop-environment, mate-desktop-environment-core), I have no idea about how to apply this. I don't know if it's possible either, as none of those 3 packages is orphan.

The only consistent way in my opinion is writing a program that is able to understand the topology of the dependency subgraph and hunt for cycles. This program would output the list of packages that are really removable, which means:
- the ones removable by apt autoremove
- the ones belonging to a dependency cycle of automatically installed programs (not removed by autoremove) that currently are not dependencies of manually installed packages on the system (independent from the metapackage)

I don't know if it was clear, it seems it's pretty hard for me to write down the problem clearly.
Thank you very much for your help in any case!

CwF
Global Moderator
Global Moderator
Posts: 2636
Joined: 2018-06-20 15:16
Location: Colorado
Has thanked: 41 times
Been thanked: 192 times

Re: Remove automatically installed dependency cycles

#11 Post by CwF »

mnalli wrote: 2021-07-29 18:44 I don't know if it was clear, it seems it's pretty hard for me to write down the problem clearly.
Yes, I for one don't get your issue.
A program that
mnalli wrote: 2021-07-29 18:44 a program that is able to understand
yes, apt, aptitude, synaptic...
Everything can be installed without a meta package, even without tasksel. My xfce's have none.

Also turn off suggested packages, they can bring in the whole farm.

You have not absorbed the full capabilities of the more than adequate tools mentioned.
mnalli wrote: 2021-07-29 18:44 - the ones removable by apt autoremove
simple, don't use it, or mark package status manually. Synaptic will miss nothing, obsoletes, orphans, manual, automatic, etc.

mnalli
Posts: 18
Joined: 2021-07-28 14:50

Re: Remove automatically installed dependency cycles

#12 Post by mnalli »

You have not absorbed the full capabilities of the more than adequate tools mentioned.
I think you are right in a way, but it does not seem to me that synaptic or aptitude are able to do that. These tools, as far as I see, are only as capable as apt autoremove in removing unused packages, which means that they also fail in automatically removing automatic packages that are part of a dependency cycle, and so these packages keep on being installed on the system, even if they are completely unused.

For example, after I remove the package task-mate-desktop, synaptic was not able to remove mate-desktop, mate-desktop-environment, mate-desktop-environment-core. If I went in Status > Installed (autoremovable) those packages did not show up at all, even if there was no external package depending on them. I had to find and remove them manually, and with them many other packages.
Everything can be installed without a meta package, even without tasksel. My xfce's have none.
Yes, this is clear, but my problem is more related to the removal than with the installation.

An option would be the one of doing the work manually, but it's time consuming and we can't really be sure that we have deleted all the unused packages.

CwF
Global Moderator
Global Moderator
Posts: 2636
Joined: 2018-06-20 15:16
Location: Colorado
Has thanked: 41 times
Been thanked: 192 times

Re: Remove automatically installed dependency cycles

#13 Post by CwF »

mnalli wrote: 2021-07-29 19:54 An option would be the one of doing the work manually, but it's time consuming and we can't really be sure that we have deleted all the unused packages.
Obviously, because "it's there and I don't use it" is NOT a category!

When a package is "unused" the categories are first if it was manually installed, then no further logic - you put it there, Next a package was required as a dependency or recommendation. If that package was automatically installed and you installed the package that called for it, it is then an orphan once you remove the parent package.. If the package was pulled from the repo, then it's obsolete. All tools can determine this status.

In synaptic, when working on either obsolete or orphaned packages it will tell you what else it would like to remove for your review. It's parsing this magic tree of dependency right on the screen in real time...

So, no, there is no other category of 'unused' packages. With that said, there are many packages that may have dependencies that are not really needed. More rare, dependencies not for install, but for full function are why meta packages exist. Sometimes the boundary between dependency and recommendation is blurry. As stated above, you can remove a meta package and rectify the keep status in a single session.

mnalli
Posts: 18
Joined: 2021-07-28 14:50

Re: Remove automatically installed dependency cycles

#14 Post by mnalli »

CwF wrote: 2021-07-29 20:19
mnalli wrote: 2021-07-29 19:54 An option would be the one of doing the work manually, but it's time consuming and we can't really be sure that we have deleted all the unused packages.
Obviously, because "it's there and I don't use it" is NOT a category!

When a package is "unused" the categories are first if it was manually installed, then no further logic - you put it there, Next a package was required as a dependency or recommendation. If that package was automatically installed and you installed the package that called for it, it is then an orphan once you remove the parent package.. If the package was pulled from the repo, then it's obsolete. All tools can determine this status.

In synaptic, when working on either obsolete or orphaned packages it will tell you what else it would like to remove for your review. It's parsing this magic tree of dependency right on the screen in real time...

So, no, there is no other category of 'unused' packages. With that said, there are many packages that may have dependencies that are not really needed. More rare, dependencies not for install, but for full function are why meta packages exist. Sometimes the boundary between dependency and recommendation is blurry. As stated above, you can remove a meta package and rectify the keep status in a single session.
I don't really understand how this could be comfortably done with synaptic. For example let's say that we want to remove the package task-mate-desktop. We can remove it and we can remove also all the packages under Status > Installed (autoremove). These will not include the cycles installed automatically (e.g. mate-desktop, mate-desktop-environment, mate-desktop-environment-core) because as they are dependent on each other, none of them will ever be considered as orphan: to remove those kind of packages we should look from synaptic for the dependencies of the root package (task-mate-desktop) and recursively on the dependecies of its dependencies and so on, to check whether they are installed or not. This seems really uncomfortable to do manually.

I think in this cases it would be useful to have a program that removes the whole dependency subgraph (rooted in task-mate-desktop), with the exclusion of packages that are manually installed or that are dependencies of other completely separate packages (external to the subgraph).

CwF
Global Moderator
Global Moderator
Posts: 2636
Joined: 2018-06-20 15:16
Location: Colorado
Has thanked: 41 times
Been thanked: 192 times

Re: Remove automatically installed dependency cycles

#15 Post by CwF »

Have you tried how I said to, no...
Click around a bit!
Mark it, then review the marked changes...
There is no danger, that 'Apply' button doesn't need pressed to answer your questions.
mnalli wrote: 2021-07-29 22:00 how this could be comfortably done with synaptic
so ya know, you can take down to the point you need aptitude to build it back up, comfortably!

mnalli
Posts: 18
Joined: 2021-07-28 14:50

Re: Remove automatically installed dependency cycles

#16 Post by mnalli »

CwF wrote: 2021-07-29 22:23 Have you tried how I said to, no...
Click around a bit!
Mark it, then review the marked changes...
There is no danger, that 'Apply' button doesn't need pressed to answer your questions.
mnalli wrote: 2021-07-29 22:00 how this could be comfortably done with synaptic
so ya know, you can take down to the point you need aptitude to build it back up, comfortably!
Yes, I tried. Actually I always use synaptic and look for the packages manually in this cases, but it is annoying that you have always to "look before you leap" and that you can't be fully sure if you have removed all the packages possible. At list in theory, this could be easily implemented with some simple visits of the dependency subgraph. For a large number of dependencies, using the manual method could be also pretty time consuming.

Anyway thanks to everybody for your replies, now I have much clearer ideas. What I wanted to know is that the manual method is the one that is meant to be used in this context. Maybe when I have time I will try to implement a python script to do that automatically and see if its possible.

mnalli
Posts: 18
Joined: 2021-07-28 14:50

Re: Remove automatically installed dependency cycles

#17 Post by mnalli »

UPDATE: I was wrong on most of the things that I wrote. For some reasons I was sure that apt was not able to remove cycles of dependencies of packages that were automatically installed, while this is no problem for apt: the reason why those packages were not automatically removed once removed the root package was that they were (directly or indirectly) suggested by other packages.

Now I set the option Apt::AutoRemove::SuggestsImportant=false in the configuration of apt so that packages that are only suggested are automatically removed. This makes autoremove more aggressive and suggested packages are retained only if marked as manual, which I think gives me more control.

CwF
Global Moderator
Global Moderator
Posts: 2636
Joined: 2018-06-20 15:16
Location: Colorado
Has thanked: 41 times
Been thanked: 192 times

Re: Remove automatically installed dependency cycles

#18 Post by CwF »

mnalli wrote: 2021-08-09 16:54 Apt::AutoRemove::SuggestsImportant=false
CwF wrote: 2021-07-29 19:02 Also turn off suggested packages, they can bring in the whole farm.
I could have been more clear!
Looks like you're getting it!

mnalli
Posts: 18
Joined: 2021-07-28 14:50

Re: Remove automatically installed dependency cycles

#19 Post by mnalli »

CwF wrote: 2021-08-09 17:07
mnalli wrote: 2021-08-09 16:54 Apt::AutoRemove::SuggestsImportant=false
CwF wrote: 2021-07-29 19:02 Also turn off suggested packages, they can bring in the whole farm.
I could have been more clear!
Looks like you're getting it!
Thank you very much anyway, now it makes so much more sense!

Post Reply