Friday, 28 November 2014

Fixing dependencies and autoremove packages in ubuntu

If you are a developer, then you might install various packages and remove them when work is over, or you get a better solution. However, most packages are not standalone, i.e they have dependencies on other packages, which apt-get  installs automatically. apt-get is really a very nice package manager. It internally keeps a list of what packages were installed automatically and which were manual. So, if you remove a package you manually installed, you might not want the other packages that were installed as a part of the dependency. 
    
     Here is a very nice answer from stackexchange:

Now apt implements an Auto-Installed state flag to keep track of these packages that were never installed explicitly. When you uninstall a package you can add the --auto-remove option to additionally remove any packages which have their Auto-Installed flag set and no longer have any packages which depend on it being there (a package may also be kept if another suggests or recommends it depending on the value of the APT::AutoRemove::RecommendsImportant and APT::AutoRemove::SuggestsImportant configuration options).
I would have a look at the list of packages and decide if they are worth keeping, sometimes packages which you may wan to keep are marked Auto-Installed by default. You can get information on what the various packages do by doing apt-cache show package_name. If you decide to keep some, you can use apt-mark manual followed by the names of the packages you want to keep.
Note that usually you would want to have library packages (most packages beginning with lib) marked as Auto-Installed since there are few reasons to have these packages installed on their own - other programs usually require other libraries to run, but they are little use on their own. Even if you are compiling software against the library to need the development package (ending in -dev) which depends on the library itself, so no need to explicitly install the library.
Also using aptitude, you can do aptitude unmarkauto from the command line or change within the curses interface. Within the package lists in the interface, all automatically installed packages have an A next to them. You can change this state by using m to mark an auto installed package as manual and M to mark as manual again (also l to open a search dialog and Enter to view package details)
This pretty much explains everything.

 Now, sometimes it happens that a package is installed without its dependencies, so obviously it does not work. apt-get keeps a list of the unmet dependencies.  You can resolve theses dependencies ,i.e install the packages required by

                                           sudo apt-get -f install

This will install the dependencies and your package will work as expected.


Now, as said earlier, how to get rid of packages that were installed as a part of dependency and no longer required? Here it is

                                          sudo apt-get autoremove

This removes the packages and frees up disk space.





No comments:

Post a Comment