Kieyokoe nge-Blogging
URL Submission

Collection of 18 Popular APT & DPKG Tips for Debian and Ubuntu



This is a guide containing the most popular and useful ways of using the APT and DPKG commands, and it applies to both Ubuntu and Debian (and their derivatives). I mentioned where super user privileges are required, the ones without a mention can be executed as normal user. If you're using Ubuntu, precede a command with sudo in order to gain root privileges (and enter your user password); on Debian, type su, enter the root password, and then type in the commands as shown below.

dpkg -L package_name
This command will show what files package_name installed on your computer. Notice that this works only for already installed packages. Example:

embryo@debian:~$ dpkg -L vorbis-tools
/.
/usr
/usr/bin
/usr/bin/ogg123

apt-get build-dep package_name
(needs root privileges)
This is a very useful command, which will install all the development libraries needed by an application. So if you need to compile a newer version of a program than the one included in the repositories, use this command to fetch the dependencies. Notice that the libraries installed will be for the current version coming with the repositories, so you may need to install additional libraries if needed. However, this usually works for most of the applications. Example:

apt-get build-dep wesnoth

This will fetch all the development packages needed for Wesnoth. Keep in mind that your sources repositories must be enabled (they are enabled by default in Ubuntu).

apt-get clean (and apt-get autoclean)
(needs root privileges)
This command will remove the archives installed on your system. Whenever you install a package, it is downloaded and the DEB package is kept inside the /var/cache/apt/archives/ directory. This command removes those packages, freeing up space.

apt-get clean
apt-get autoclean

Regarding apt-get autoclean: this command will remove only the archives which are no longer available in the repositories, and will keep the ones which are currently available. Helpful if you want to get rid of old archives which have been updated, but still want to keep the upgraded ones just in case. To see how much space the archive occupy, use du -h (the -h argument stands for human readable, so it will show sizes in human readable format):

du -h /var/cache/apt/archives/

apt-cache show package_name
Will show information about any package in the repository. You only have to type in the name of it, not the entire name and version. Example:

embryo@debian:~$ apt-cache show vorbis-tools
Package: vorbis-tools
Priority: optional
Section: sound
Installed-Size: 580
...

apt-cache search pattern
Will search and list all the packages which contain pattern in their name or in their description. You can pipe this with grep for more relevant results:

embryo@debian:~$ apt-cache search gnome terminal|grep terminal
gmfsk - MFSK, RTTY and other digital mode terminal for HF/amateur radio
gnome-terminal-data - Data files for the GNOME terminal emulator
gnome-terminal - The GNOME 2 terminal emulator application

apt-get update && apt-get upgrade
(needs root privileges)
This is a one-liner to update your packages list and upgrade your system. Since it requires root privileges, if your distribution is Ubuntu use sudo apt-get update && sudo apt-get upgrade. Notice that the second command (after the double ampersand) is executed only if the first one was successful, so if fetching any of the lists fails, the second command will not be executed. If you're running a testing or beta release, use instead the following:

sudo apt-get update && sudo apt-get dist-upgrade

This will fetch updates even if they depend on newer packages.

dpkg --get-selections
This command will list all the packages installed on a system using the package manager. Example:

embryo@debian:~$ dpkg --get-selections
acpi-support-base install
acpid install
adduser install
akregator install
...

dpkg -S filename
Will list the packages which install filename. Example:

embryo@debian:~$ dpkg -S oggenc
vorbis-tools: /usr/share/man/man1/oggenc.1.gz
vorbis-tools: /usr/bin/oggenc
embryo@debian:~$

apt-get autoremove
(needs root privileges)
This command will remove unnecessary packages (e.g. orphaned packages), which are no longer needed by any of the packages installed in the system. This happens often after you uninstall a certain application, and its dependencies still remain installed on the system. Use this command to get rid of them.

apt-cache dump
This command will list every package in the cache.

apt-cache depends package_name
A very useful command which lists every dependency a package has, including recommended packages.

embryo@debian:~$ apt-cache depends vorbis-tools
vorbis-tools
Depends: libao2
Depends: libc6
Depends: libcurl3-gnutls
...

apt-cache rdepends package_name
Will show dependencies in reversed order, that is, it will list all the packages which depend on the specified package.

apt-cache rdepends mplayer

apt-cache policy package_name
This will list the repository in which a package is located. In Ubuntu, there are four such repositories: main, restricted, universe and multiverse. Debian has main, contrib and non-free. There is a certain policy for each package, and depending on that, the package is included in one of the specified repositories.

apt-cache policy amarok
apt-cache policy sun-java6-jre

apt-cache showsrc package_name
Will show information about a package source.

apt-get -f install
(needs root privileges)
Will try to fix broken dependencies. This usually comes in handy if you try to manually install a DEB package without installing first its dependencies. Run apt-get -f install to fix the missing dependencies and try to install the package again.

apt-cdrom add
(needs root privileges)
Will add a CD ROM to your sources, so you can install packages from it. This command is mostly useful if you have some ISO images, which you don't want to burn to a CD. In order to scan the ISO images, use:

apt-cdrom -d=/cdrom add

This will mount the ISO image inside the /cdrom directory, and then add its contents to the sources.list. Notice that the /cdrom directory has to be empty. You can use any empty directory for this:

apt-cdrom -d=/home/USER/mydir

dpkg -c local_file.deb
The -c argument tells dpkg to list the contents of a DEB package. Example:

embryo@debian:~$ dpkg -c google-chrome-stable_current_i386.deb
...
drwxr-xr-x root/root 0 2010-07-30 23:54 ./usr/share/man/man1/
-rwxr-xr-x root/root 3098 2010-07-30 23:54 ./usr/share/man/man1/google-chrome.1
lrwxrwxrwx root/root 0 2010-07-30 23:54 ./usr/bin/google-chrome -> /opt/google /chrome/google-chrome

dpkg -f local_file.deb
This shows the control file for a binary package. A control file is a file which provides information to the package manager about dependencies, maintainer, homepage, description, and more.

embryo@debian:~$ dpkg -f google-chrome-stable_current_i386.deb
Package: google-chrome-stable
Version: 5.0.375.126-r53802
...

These are the most popular uses of APT and DPKG. Have some more? Please, share them!

BEGUNDELZ MANIAC. Diberdayakan oleh Blogger.