What is Package Management ?
A 'Package Management System' or 'Package Manager' is a collection of tools used to automate the process of installing, updating, configuring, and removing of software packages for a computer's operating system in a consistent manner. Different operating systems have their own package managers. For instance, this is a list of package management tools used by different operating systems. [Courtesy: Wikipedia]
Things you should know
Debian uses the Deb package format for packing together files belonging to an application. You can look at it as something like the Setup installer (Eg: Installshield) in Microsoft Windows.
Software meant to be installed in Debian Linux has the file extension '.deb'.
Debian, (and most other Linux distributions), use a publicly accessible place on the Internet - called a repository - to store all their software packages.
The file /etc/apt/sources.list contain a list of web addresses pointing to the Debian repository.
The web address has the following syntax :
deb [web address] [distribution name] [options]
An example of a web address pointing to the Ubuntu repository is shown below.
deb http://in.archive.ubuntu.com/ubuntu breezy main restricted
Managing software in Debian
Debian (and related) Linux (distributions) use two important command line tools to manage deb packages. They are -
- Dpkg, and
- Advanced Packaging Tools or APT
Dpkg - The low level package management tool
Here are a few ways of using dpkg in Debian Linux.
Install a package
dpkg -i <package-name>
Example : Let's say you want to install Gedit text editor in Debian and you have downloaded its deb package from the Gedit website. The package is named gedit-2.12.1.deb. To install it in Debian, open a terminal and move to the directory containing the deb file and execute the command :
# dpkg -i gedit-2.12.1.deb
You can also use --install instead of -i.
Remove a package
To remove an installed package, the syntax is :
dpkg [-r | -P] <program name>
-r - Will remove the program but leave its configuration files intact. You can also use --remove instead of -r.
-P - Will completely remove the package including the configuration files. You can also use --purge instead of -P.
Continuing with the previous example, to remove Gedit (but not its configuration files) from Debian -
# dpkg -r gedit
To remove Gedit completely -
# dpkg -P gedit
Get more information
To see the contents of a deb package (Eg: gedit-2.12.1.deb), use the -c option.
# dpkg -c gedit-2.12.1.deb
To get more information about a deb package such as - the authors name,the year of compilation, a short description of its use, and so on, use the -I option.
# dpkg -I gedit-2.12.1.deb
To check if a program is installed in Debian, use the -s option.
# dpkg -s gedit
The above command also provides other details about the program such as the package maintainer, dependencies, installed version, a small description of the package and so on.
To know where all the files associated with a program are installed, use the -L option.
# dpkg -L gedit
Advanced Packaging Tool (APT)
APT is the Advanced Package Tool and provides the apt-get program.
apt-getprovides a simple way to retrieve and install packages from multiple sources using the command line.
Unlike dpkg, apt-get does not understand .deb files, it works with the packages proper name and can only install .deb archives from a source specified in '/etc/apt/sources.list'.
apt-get will call dpkg directly after downloading the .deb archives from the configured sources.
Some common ways to using apt-get are shown below :
To update the list of packages known by your system, do the following :
# apt-get update
You should update your package lists regularly by running the above command.
To upgrade all the installed packages on your system -
# apt-get upgrade
To install the gedit package and all its dependencies -
# apt-get install gedit
To remove the gedit package from your system -
# apt-get remove gedit
To remove gedit and also its configuration files -
# apt-get --purge remove gedit
Upgrading Debian to a new version can be done with the command -
# apt-get dist-upgrade
Saving valuable hard disk space
Each time you install an application using apt-get, the corresponding deb package is downloaded and stored in a location on your hard disk - usually in the directory '/var/cache/apt/archives/'.
The following command will remove all the archives and free up hard disk space -
# apt-get clean
To delete only those packages in the cache which are found useless or partially complete, do -
# apt-get autoclean
Another tool in the APT tool suite is apt-cache.
apt-cachetool can be used to search for and find packages, and it supports use of regular expressions.
To find all packages that contain the word "editor", do the following -
$ apt-cache search editor
To print detailed information about a package, the syntax is -
apt-cache show <package name>
To print the packages that a given package depends on, the syntax is -
apt-cache depends <package name>
To print detailed information of the versions available for a package and the packages that reverse-depends on it -
apt-cache showpkg <package name>
To get statistics of the packages available in the repositories -
$ apt-cache stats
I hope you have enjoyed reading this concise tutorial on apt-get and dpkg which will help you manage the packages in Debian Linux.