dpkg (for .deb files) and rpm (for .rpm files) are the tools that actually put packages on disk and record them. Higher level tools such as apt and dnf build on them. Use the one that belongs to your distribution.
Installing a package file
$ sudo dpkg -i hello_2.10-3_amd64.deb
$ sudo rpm -i hello-2.12-1.x86_64.rpmFor RPM, -U upgrades a package, or installs it if it is not there yet. People often add -v for more output and -h for a progress bar: sudo rpm -Uvh file.rpm.
Neither tool fetches dependencies. If something is missing, rpm refuses to install, while dpkg unpacks the package but leaves it unconfigured. To install a local file with dependencies resolved, use sudo apt install ./hello_2.10-3_amd64.deb or sudo dnf install ./hello-2.12-1.x86_64.rpm. The ./ tells the tool you mean a file.
Removing
$ sudo dpkg -r hello
$ sudo rpm -e helloRemoval takes the package name, not the file name. With dpkg, -r keeps configuration files, and -P (purge) deletes them too.
Asking questions
Querying is where these tools shine, and it normally needs no sudo.
List installed packages:
$ dpkg -l
$ rpm -qaList the files a package installed:
$ dpkg -L hello
/usr/bin/hello
/usr/share/doc/hello
$ rpm -ql helloFind which package owns a file:
$ dpkg -S /usr/bin/hello
hello: /usr/bin/hello
$ rpm -qf /usr/bin/helloOutput is shortened here. Note the difference between dpkg -l (list packages) and dpkg -L (list files).
Inspecting a file before installing
You can look inside a package that you have not installed:
$ dpkg-deb --info hello_2.10-3_amd64.deb
$ dpkg-deb --contents hello_2.10-3_amd64.deb
$ rpm -qip hello-2.12-1.x86_64.rpm
$ rpm -qlp hello-2.12-1.x86_64.rpmFor rpm, -p means the argument is a package file, not an installed package name.
This is worth doing with anything from outside your repositories, because install scripts run as root. rpm -K file.rpm checks a package's digests and signatures.
Try it
On your own system, find out where ls came from and what else shipped with it:
$ dpkg -S /usr/bin/ls # Debian, Ubuntu (older: /bin/ls)
$ dpkg -L coreutils
$ rpm -qf /usr/bin/ls # Fedora, RHEL
$ rpm -ql coreutilsThe packages, disk and FHS lab lets you try these in a live shell.
Check your understanding
rpm and dpkg
All 4 sections ยท no timer
Unlimited retries
Questions from every section are combined into one assessment. Answer them all correctly to complete the article.
Your completion saves in this browser. Sign in to sync it to your account.