4

man apt-get says:

autoremove is used to remove packages that were automatically installed to satisfy dependencies for other packages and are now no longer needed.

So why is it not automatically called every time I remove package?

EDIT

Essentially, my question is: Why use remove <pkg name> and not autoremove <pkg name> to remove packages.

See here

PS: This won't break dependency as said here

Sourabh
  • 1,761
  • 5
  • 22
  • 31
  • 1
    This comment is just to clarify to people. I think what Sourabh is basically asking is "why does apt-get remove not remove the unneeded dependencies? Why do we have to do apt-get autoremove after it? Why doesn't remove just remove the dependencies by default; is there a purpose for keeping the now unneeded dependencies? Why not just use autoremove <package> instead of remove <package>?" Correct? I think the best answer to this question would be the one that answers "is there a purpose for keeping unneeded dependencies?" – Alaa Ali Aug 27 '13 at 07:39

2 Answers2

4

See the AptGet/Howto - Ubuntu Documentation page to clear your doubts.

It says:

apt-get autoremove

This command removes packages that were installed by other packages and are no longer needed.

apt-get autoremove <package_name>

This command removes an installed package and dependencies.

and

apt-get remove <package_name>

This command removes an installed package, leaving configuration files intact.

EDIT

It depends on how much you trust the dependancy tracker. While almost always correct, there are times when you would want a dependancy to remain, particularly when you are a developer or power user installing software that is not in the repository.

If you always install software through apt-get, without exception, and trust all the dependancies to be correct (which they usually are), then you can use apt-get autoremove and gain a small amount of drive space and a reduced exposure to potential security holes by having it remove packages that no longer have any packages that need them.

But if you install software manually, or develop software, or do not want to deal with a possible dependancy error, then not using autoremove to clear potentially unused packages is probably the safer choice. Regardless of whether you use apt-get autoremove every now and then or not, you will always remove software using apt-get remove Package

For example, if I install AwesomePackage, it may depend on AwesomeLibrary, and thus AwesomeLibrary will get automatically installed as a dependancy. When I remove AwesomePackage using autoremove, as long as no other package has AwesomeLibrary as a dependancy it will be uninstalled as well. But if SuperPackage also requires AwesomeLibrary, or if I had installed AwesomeLibrary explicitly myself rather than having it come in automatically as a dependancy (apt-get install AwesomeLibrary), then autoremove would not get rid of it.

The reason it is not the default is that having AwesomeLibrary on the system, unused, is a very minor issue. It will almost never cause problems, and most dependancies don't take up much space. There are exceptions, but the times when removing a dependancy will cause problems outnumber the times when it will solve or prevent a problem.

Source: SuperUser: When would you use apt-get remove over apt-get autoremove?

Tarun
  • 4,245
  • 13
  • 50
  • 74
  • but my question is: Why not remove all packages that were installed by other packages and are no longer needed when the original package is removed, in other words, why use remove <pkg name> and not autoremove <pkg name> for removing packages. – Sourabh Aug 27 '13 at 07:21
1

Why not remove all packages that were installed by other packages and are no longer needed when the original package is removed?

Because, remove only remove the package that you want to remove, not it's dependencies. Let see:

I installed xorg which depends (among other things) of xserver-xorg. xserver-xorg is marked as Automatic, and while I keep installed xorg it will not be uninstalled by autoremove. Now, I call apt-get remove xorg, which tells apt-get to do whatever it takes to remove xorg, and since it only needs to remove that package it doesn't take further action. Why? Because you only told him to remove that package and nothing else. You didn't tell him what to do with the dependencies, nor with other packages. apt-get is a good boy and follow your order with dot and comma, without trying to be smart doing things you didn't ask him to do, and I like it that way.

With apt-get autoremove xorg you tell apt-get to do whatever it takes to remove xorg and any Automatic dependency that was installed by xorg. Then apt-get follows your order and remove xorg and xserver-xorg and any other dependency of xorg that is marked as Automatic and don't have any other dependency to fulfill.

Lets take another scenario, I installed xorg and xserver-xorg and none is marked as Automatic. If I call remove on xorg only xorg will be deleted. If I call autoremove on xorg only xorg will be deleted. If I call remove on xserver-xorg, both xserver-xorg and xorg will get deleted, because you are telling apt-get to do whatever it takes to remove xserver-xorg but since xorg also depends of xserver-xorg, apt-get don't want to leave broken dependencies while following your orders, hence delete it.

But here is the fun, if you call autoremove on xserver-xorg it will uninstall any dependency marked as Automatic of xserver-xorg and xorg itself. Weird, huh? This is because apt-get takes this set of orders from you. In a nutshell, this are the actions, in the exact order, you tell apt-get whenever you call:

apt-get autoremove xserver-xorg

  • Remove any reverse dependency of xserver-xorg. In this case xorg
  • Remove xserver-xorg.
  • Remove any package that xserver-xorg depends upon and is marked as automatic.
  • Don't do anything else.

apt-get remove xserver-xorg

  • Remove any reverse dependency of xserver-xorg. In this case xorg
  • Remove xserver-xorg.
  • Don't do anything else.

apt-get remove xorg

  • Remove any reverse dependency of xorg. In this case none
  • Remove xorg.
  • Don't do anything else.

apt-get autoremove xorg

  • Remove any reverse dependency of xorg. In this case none
  • Remove xorg.
  • Remove any package that xorg depends upon and is marked as automatic. If xserver-xorg is marked as automatic, it will get removed. If it's not it will be kept installed.
  • Don't do anything else.

As you can see, every set of order has in the end "Don't do anything else" once he fulfilled every command. That is why you only remove only the target with remove.

Braiam
  • 67,791
  • 32
  • 179
  • 269