October 12, 2018

Debian packages and "apt"

Debian packages are managed with "apt-get" (along with "apt-cache"). The packages themselves are ".deb" files, and are actually "ar" archives, but you don't need to know any of that to work with them. You could use the "dpkg" utility to work with them, but this is more primitive, and "dpkg" is rarely used directly. Apt is a nice front end for dpkg. Some things I know how to do with dnf/rpm on Fedora that I do not yet know how to do with apt:
How do you get a list of all installed packages?
How do you get a list of all available packages in the repos?
How do you know what package a file belongs to?
How do you list the files in a package?

A short cheat sheet

Most of these commands must be run as root to work. I use "su" to become the root user, but true debian diehards will use sudo in front of every command.

apt-get update will update the package database on your system. This is pretty much a prerequisite before doing anything else with apt.

apt-get install package installs the specified package.

apt-get upgrade package upgrades the specified package.

apt-get remove package remove the specified package.

The "-s" switch is for "simulate" and will show you what is going to be done without actually doing anything. The "-y" switch says to answer yes to any subsequent questions. The "-d" switch says to download a package (to /var/cache/apt/archives) without actually installing it.

Searching using apt-cache

apt-cache search something

apt-cache show package

apt-cache policy package

Other things

I want to learn the following:
How do you get a list of all installed packages?
How do you get a list of all available packages in the repos?
How do you know what package a file belongs to?
How do you list the files in a package?

How do you get a list of all installed packages, and so forth?

Either of the following:
dpkg -l > pkg.list
apt list --installed > pkg.list
apt list | grep -v "installed"
apt list --all-versions package

How do you get a list of all files in a package?

To see all the files a package installed onto your system, do this:
dpkg-query -L 

To see the files a .deb file will install

dpkg-deb -c 

To see the files contained in a package NOT installed, use apt-file (which you may need to install).

apt-file list 
If you need to install apt-file:
su
apt-get install apt-file
apt-file update

How do I find out what package provided (or provides) a file.
dpkg -S /bin/ls
dpkg-query -S '/bin/ls'
apt-file search date

Comments? Questions? Drop me a line!

Adventures in Computing / [email protected]