When you install a program like postgresql, it installs several programs for its last version.
Once installed how remove all those packages? because using
apt-get remove postgresql
removes only that head package
aptuninstall
When you install a program like postgresql, it installs several programs for its last version.
Once installed how remove all those packages? because using
apt-get remove postgresql
removes only that head package
apt-get autoclean
will just remove old versions from the package archive, but won't change anything for installed packages.
To remove a package use sudo apt-get purge package
. This should uninstall any dependencies, but won't full remove them. I use the command aptitude purge ~c
to `.clean all uninstalled packages.
Even purged packages may leave behind data files and backup files. Backups should be a directory under in /var/backup
. Data files will likely be in /var/lib
. I would backup the data files before removing them in case some other application uses them. You may want to grep the data file directory in /var/lib/dpkg/info
. If any files use the directory, then keep it. For example to find which packages installed use /var/lib/ldap
, I run the search grep -l /var/lib/ldap /var/lib/info/dpkg/*
. If you have a lots off packages you may need to use find /var/lib/dpkg/info | xargs grep -l /var/lib/ldap
.
EDIT: You can list all programs which could be marked as automatically installed with the command aptitude search '~i!~M?for x: ~D( ~i!~M )'
. Pipe this to the commands 'cut -d\ -f4 | sudo aptitude markauto` to mark these packages as auto-installed.
I then use the command aptitude search '~i!~M'
(installed, not automatically installed) to list all the first order installed packages. WARNING: When removing packages, you may uninstall packages you want to keep. Simulate the removal first, and unmarkauto any packages you want to keep before run the real removal.
EDIT2: Above instructions includes packages suggested by other packages as first level packages. To list these use the command aptitude search '~i!~M?for x: ~Rsuggests:( ~i!~M )'
. If desired, these can be marked using the same pipeline as for other dependencies. However, you must configure suggested packages to be automatically installed, or all the suggested packages and their depencies will be automatically uninstalled. This is done by adding the line APT::Install-Suggests "true";
to /etc/apt/apt.conf
or a file in /etc/apt/apt.conf.d
.
Dependencies may lead to unexpected selections for first level packages. If neither wordpress
is marked wordpress-l10n
then wordpress-l10n
is considered the first level install. Normally wordpress-l10n
would be marked as automatically installed, so this would not be a problem. You will likely get a lot of cruft this way.
gnome-core
is a meta package and the case with meta packages is --
They pull packages to get installed but removing them will not remove all the pulled packages.
So, unless, you have copied the names of packages installed by gnome-core, it is virtually impossible to remove all the 600 MBs.
But, you can get the names of pulled packages by the command
apt-cache depends gnome-core
and try to remove the packages one by one. You should check always whether it is removing any necessary packages.
Or you can get the list of packages in more useful way by this:
apt-cache depends gnome-core | cut -f 2 -d ':' | tr '\n' ' '
This will list all the dependencies of gnome-core package, ignore the package name in <>
marks only.
When you see a lot of space is being freed from the command, (more that 600MB), you should know that you are removing more than you installed. apt-get
will let you know how much space is going to be freed, before removing like with a message like this
After this operation, 384 kB disk space will be freed.
And When you try to remove essential system package, apt-get
will show you a warning message.
Recommendation: I suggest you to get a list of packages from the first command, and try to remove them one by one. It is safer. If you see a warning, skip removing that package. I see, most of the packages in gnome-core are related with GUI, I guess removing those packages will not harm your system (if you don't want a GUI).
Hope this helps!
When you install a package and that package depends on some other packages, the dependency packages also get installed and Marked as auto. That means, the Apt system mark them as Automatically installed as dependency of another package. It helps Apt system to recognize unnecessary packages.
When, you uninstall the master package, the pulled packages are also marked as obsolete or unnecessary packages in the system. You can remove them by providing autoremove
option to apt-get
. (aptitude automatically remove them with the master package).
An exception to this rule is, if you later install another package which also depends on the pulled packages, the pulled packages will not be marked as obsolete when you remove the first master package.
Example: You installed a package X
that depends on package Y
. When you installed X
, Y
also gets installed and marked as auto. If you do not install another package Z
which also depends on Y
, removing X
will render Y
's usefulness and Apt system will mark it obsolete and you can remove it with autoremove
option.
But If you install a package Z
after X
which also depends on Y
, then removing only X
does not mark Y
as obsolete package and you can't remove it with autoremove
option
But note that if you remove package Y
after installing X
, it will remove package Y
including X
, because X
can't stay without Y
and you wanted you remove Y
, that means you also wanted to remove X
. Apt will remove X
automatically when removing Y
unlike marking it obsolete to later removal by autoremove
option.
Try out examples: ubuntu-desktop
package is a meta package. It was used to install the standard Ubuntu desktop. Try removing it, only that package will be removed.
Also try installing lubuntu-desktop
package (You may not want to install this, because it is a big download). But, when you try to remove it, only the tiny package lubuntu-desktop
will get removed.
The meta packages like gnome-core, ubuntu-restricted-extras are also called virtual packages. They are called so, because they are basically empty packages, They pull other packages by depending on them. For example, ubuntu-restricted-extras depends on (in 12.04) following packages:
ubuntu-restricted-addons
ttf-mscorefonts-installer
unrar
gstreamer0.10-plugins-bad-multiverse
libavcodec-extra-53
Where, ubuntu-restricted-addons itself is another meta package. Since, meta packages are used for only pulling packages, installing them does not mark the pulled packages as auto, they are marked as manually installed. The result? Removing only the master meta package will not mark the pulled packages obsolete and you can't remove them by autoremove
option. That is why you need to remove each pulled package of the meta packages manually.
Example: You installed a meta package X
that depends on packages Y
and Z
. When you installed it, the Y
and Z
packages aren't marked as auto (automatically installed as dependency of another package), instead they marked as manually installed. In later time when you want to remove X
, only the virtual X
package gets removed. Both, Y
and Z
, remain in the system and you can't uninstall them with autoremove
option.
Best Answer
As
apt-get autoremove
(suggested by Aaron) will remove all "helper-packages" nothing seems to depend on any longer, sometimes you want to keep some of them for one reason or another. So if that concerns you, another possibility would be:Using Bash as your shell, this would basically do the following:
apt-cache depends postgresql
would list all packages the postgresql depends on, including postgresql itself. But each line would look likedepends on: <package>
-- so we pipe the output to...awk '{print "sudo apt-get remove "$NF}'
which would take the last word on each line (which is the package name), and prints it out after preceding it with our intended command:sudo apt-get remove
(you could of course also useapt-get purge
instead).$()
construct, we advise Bash to interpret the output as command to be executed.You could alternatively replace the 3rd step and instead redirect the output into a file:
And then inspect the file, optionally do some adjustments (such as commenting out/removing lines where you want to keep a package), and finally execute the script using
Now you have a lot of possibilities to chose from :)
EDIT: Checking with more complex metapackages as e.g. lubuntu-desktop, above statements needs to be refined:
The
grep
is needed to restrict the result to dependencies (and skip the recommends etc.).IMPORTANT: You should use this only for metapackages!!! otherwise, you may end up with an empty disk (e.g. postgresql-9.1 depends on libc6, and removing libc6 will certainly backfire as it is needed by a lot of packages).
So be careful, and better redirect to a file first (as explained) and investigate before execution.