Apt for beginners , how to manage Ubuntu/Debian packages

Debian and its forks, Ubuntu , Linux Mint , Bodhi Linux etc. are the most popular and newbie friendly GNU/Linux distributions. Their software packages are managed by apt and dpkg. In this tutorial we are going to talk about few useful and time saving  apt commands for beginners.

Apt is closely related to dpkg , if you are not familiar with dpkg , have a look on our dpkg tutorial for beginners.


A little about apt-get and apt-cache

Apt stands for Advanced Packaging Tool,  apt-get and apt-cache are the two most used apt command. Apt-get is used for installing, removing, purging, upgrading, even upgrading entire system while apt-cache is mainly used for searching available software packages.


A little about /etc/apt/sources.list file

This file contains a list of software package source, one of the most vital file for installing or updating anything with apt. The sources.list file could have many active sources and a supports a wide range of of source media like a HTTP or FTP server, from a local filesystem, a CD/DVD ROM even from a SSH server. The entries in sources.list file normally looks like bellow.

sources.list file

file type:  Or  archive type, the first word of each line , either deb or deb-src , deb for pre-compiled binary packages and  deb-src for original software source code file with some debian specific components. The deb file type is most used.

repository URL: This is the URL from where software packages will be downloaded. It may be different for different type of sources.

distribution: Your Current distribution name, like sid , stretch  , jessie , wheezy etc. for Debian and precise , trusty etc. for Ubuntu.

Component: Type of software sources, like main , contrib , non-free , universe , multiverse etc.

main : The Debian main software source, which contains only Debian specific free softwares only, no third party dependency.

contrib : Contributed by other projects, may have third party dependency.

non-free : This repository contains closed source and reverse engineered closed source software, like non-free graphics drivers, Win-RAR , NTFS-3G etc. etc.

universe : This repositary is Ubuntu specific, contains a mix of free and non-free software.

multiverse : This one is Ubuntu specific too, contains a large software collection, these softwares are not maintained by Ubuntu.

After changing any line of /etc/apt/sources.list file, running apt-get update is necessary to make the changes available.


Useful apt-cache commands

1. Search possible packages

 apt-cache search package_name 


2. Show detailed information about a package

 apt-cache show package_name
 apt-cache show kde-plasma-desktop # example 


3. Show all dependency of  a package

This one is really helpful if you want to clean up your system, check package dependency before removing it.

 apt-cache depends package_name 
 apt-cache depends kwrite  # example 


4. Check reverse dependency of a package

This command is very useful if you want to cleanup your system without breaking something. Before cleaning any package, check its reverse dependency, i.e. whic other package/packages depends on this package.

 apt-cache depends package_name 


5. Show available source code of packages

If you want to compile a package from source code, deb-src repository enabled enabled for this command

 apt-cache showsrc package_name 


Useful apt-get commands

1. How to install one or more package

 sudo apt-get install package_1  # install a single package 
 sudo apt-get install package_1 package_2  # install many package 
 sudo apt-get install vim-gnome  # example 


2. Remove a package, but keep configurations

 sudo apt-get remove package_neme 


3. Totally remove a package,

This command will remove a package completely and its dependency including user made configuration changes.

 sudo apt-get purge package_name 
 sudo apt-get purge kwrite 


4. Fix missing dependency problem

Very useful if you manually installed a package with dpkg and it returned a dependency error

 sudo apt-get install -f 


5. Clean up unnecessary installed packages

 sudo apt-get autoremove --purge 


6. Clean up apt cache, free some disk space.

 sudo apt-get clean 



Leave a Reply

Your email address will not be published. Required fields are marked *