VMware ESXi and vSphere Cluster Management
Debian Package Manager: Managing .deb Packages with dpkg and APT
Learn how to install, remove, list, inspect, and query Debian .deb packages with dpkg, and use APT to resolve dependencies and install software safely.
Debian-based Linux systems use a package-management system to install, update, inspect, and remove software. The low-level tool for working with local Debian packages is dpkg. The higher-level system, APT, obtains packages from repositories and resolves dependencies.
This lesson applies to Debian and Debian-based distributions such as Ubuntu, Linux Mint, and Knoppix.
What Is the Debian Package Management System?
A Debian package is software formatted for installation on Debian-based systems. A binary Debian package commonly has the .deb filename extension. It contains program files, metadata, installation scripts, and dependency information.
A package manager maintains software in a controlled way. It can install program files in the correct locations, record which files belong to which package, track versions, preserve or remove configuration, and coordinate dependencies.
A dependency is another package required by software. For example, an application may depend on a shared library or a command-line utility. Installing only the application file may not be sufficient if those requirements are missing.
The Role of dpkg
dpkg is Debian's low-level package tool. It works directly with local .deb archives and the local package database, which records package names, versions, architectures, files, and installation states.
- Install a local package archive.
- Remove or purge an installed package.
- List package records and their status.
- Query metadata for installed packages.
- Inspect the contents and metadata of a local
.debfile.
dpkg does not normally search configured software repositories, download packages, or automatically find and install missing dependencies. Those are higher-level APT functions.
Installing a Local .deb Package with dpkg
Use the -i option, short for install, with the path to the local package file:
sudo dpkg -i ./example-package_1.0_amd64.deb
sudo runs the operation with administrative privileges. Package installation normally requires root access because files are written to system directories and the package database is changed.
Identifying the Package File
A path beginning with ./ means “a file in the current directory.” You can list files in the current directory with:
ls
If the file is in another directory, provide its path, for example:
sudo dpkg -i /home/alex/Downloads/example-package_1.0_amd64.deb
Be precise about spelling, capitalization, version numbers, and architecture suffixes such as amd64 or arm64. The package filename is a file path; the package name used for later queries may be only part of that filename.
What Happens When Dependencies Are Missing?
dpkg can unpack a package and begin its installation without being able to complete configuration. If required packages are absent, it reports dependency errors and the package may remain in an unconfigured or partially configured state. dpkg does not download those dependencies itself.
For a local package, APT is often more convenient because it can obtain dependencies from configured repositories:
sudo apt install ./example-package_1.0_amd64.deb
Removing Packages with dpkg
To remove an installed package, use its package name, not necessarily the name of the downloaded file:
sudo dpkg -r example-package
The -r option removes the program files while commonly retaining the package's system configuration files. Keeping configuration can be useful if you plan to reinstall the software.
To remove the package and its associated configuration files, use purge:
sudo dpkg -P example-package
Do not remove a package casually. Other installed software, or core system components, may depend on it. Review the command and its consequences before confirming a removal. APT may be safer for dependency-aware removal because it can show related changes.
Package Name Versus .deb Filename
A file such as example-package_1.0-2_amd64.deb typically contains the package name example-package, but the filename also includes version and architecture information. Commands such as dpkg -r, dpkg -P, and dpkg -p generally expect the package name recorded in the database.
Listing Installed Packages
Display package records and status information with:
dpkg -l
The listing uses a compact status format. The first three columns describe the package state:
- Desired action: what the system wants to do, such as install, remove, or purge.
- Current status: whether the package is installed, not installed, or only partly configured.
- Error state: an additional problem indicator when a package needs attention.
The common ii beginning means the package is selected for installation and is currently installed. An entry beginning with rc commonly means the package was removed but its configuration files remain. Entries with other combinations can indicate that installation, removal, or configuration is incomplete.
Filtering the Listing
To search for a package-name pattern, provide a pattern directly to dpkg:
dpkg -l 'example-package*'
You can also filter the full listing with grep:
dpkg -l | grep example
Filtering is useful when the exact package name is unknown, but plain text matching can return partial matches. For example, searching for lib may match many unrelated package names and descriptions. Check the complete package name and status before acting on a result.
Querying Package Information
Metadata for an Installed Package
Use dpkg -p with an installed package name:
dpkg -p example-package
The output can include the package name, version, architecture, description, dependencies, and other metadata recorded in the installed-package database. This command queries the database; it does not inspect an arbitrary filename.
Metadata Inside an Uninstalled .deb File
Use dpkg -I to examine the control information stored inside a local archive before installing it:
dpkg -I ./example-package_1.0_amd64.deb
This is useful for checking the package name, version, architecture, description, and declared dependencies. It is also a way to detect an architecture mismatch before installation.
Files Installed by a Package
To list files recorded as belonging to an installed package, use:
dpkg -L example-package
This helps locate executables, libraries, documentation, configuration templates, and other files installed by the package.
Common dpkg Operations
| Task | Command form | What it does | Important note |
|---|---|---|---|
| Install local package | sudo dpkg -i ./package-file.deb | Unpacks and attempts to configure a local Debian package. | Does not download or resolve missing dependencies. |
| Remove package | sudo dpkg -r package-name | Removes the installed package. | Configuration files are generally retained. |
| Purge package | sudo dpkg -P package-name | Removes the package and its configuration files. | Use the package name, not usually the archive filename. |
| List packages | dpkg -l | Displays package records and status indicators. | Review the status columns carefully. |
| Show installed-package metadata | dpkg -p package-name | Displays metadata from the local package database. | The package must be known to dpkg. |
| Inspect a local .deb file | dpkg -I ./package-file.deb | Displays control information inside an archive. | Works before installation. |
| List package-owned files | dpkg -L package-name | Lists files installed by a package. | Usually requires an installed or recorded package. |
Dependencies and dpkg's Limitations
Packages declare dependencies so that required libraries, services, interpreters, and supporting programs are present. A dependency can also require a minimum version or a compatible package relationship.
When you install a downloaded archive with dpkg, several situations can cause errors:
- A required package is not installed.
- The required version is unavailable.
- The package was built for a different distribution release.
- The package architecture does not match the system.
- Repository metadata is outdated or the needed repository is not enabled.
After a dependency-related dpkg failure, ask APT to repair the package state:
sudo apt --fix-broken install
The traditional apt-get form is:
sudo apt-get -f install
Review the proposed installations, removals, and upgrades. If the proposal is unexpected, cancel it and investigate before continuing.
APT: The Higher-Level Package Manager
APT, or Advanced Package Tool, works with configured repositories. A repository is a source of package files and package metadata. APT can download packages, select compatible versions, calculate dependency relationships, and coordinate installation or upgrades.
apt-get is a traditional command-line interface for APT. aptitude is another higher-level interface and can also help resolve dependency choices. The apt command is commonly used interactively on modern Debian-based systems.
| Capability | dpkg | APT, apt-get, or aptitude |
|---|---|---|
| Install local .deb files | Yes, directly. | Yes; APT can install a local file and resolve dependencies. |
| Install from repositories | No repository search or download. | Yes. |
| Dependency resolution | No automatic resolution. | Yes, using repository metadata and available packages. |
| Package download | No. | Yes. |
| Package database access | Direct low-level access. | Uses dpkg underneath for Debian package state. |
| Typical use case | Inspecting records or installing a known local archive. | Routine installation, updates, upgrades, and dependency-aware changes. |
Safe Repository Installation Workflow
Refresh package metadata before installing software from repositories:
sudo apt update
sudo apt install example-package
apt update downloads current repository metadata. It does not itself upgrade installed packages. The following apt install command selects the package and resolves its dependencies.
For a downloaded local package, use the explicit path with APT:
sudo apt install ./example-package_1.0_amd64.deb
The ./ is important: without a path, APT treats the argument as a repository package name rather than a local file.
Package Removal Choices
| Operation | Command | Program files removed | Configuration files retained | When to use it |
|---|---|---|---|---|
| Remove | sudo dpkg -r package-name | Yes | Generally yes | Uninstall software while preserving configuration for a possible reinstall. |
| Purge | sudo dpkg -P package-name | Yes | No | Remove the software and its package-managed configuration. |
Troubleshooting
dpkg Reports Unmet Dependencies
The local package requires packages that are not installed or configured. Run sudo apt --fix-broken install or sudo apt-get -f install, then inspect the proposed changes. If APT cannot find a dependency, update metadata and verify that the package targets the current distribution release.
A Package Cannot Be Removed
Other installed packages may depend on the target. Inspect the dependency implications before proceeding. Remove dependent software only when you understand the effect; otherwise, keep the required package installed.
dpkg -p Cannot Find a Package
The supplied value may be a filename instead of an installed package name, or the package may not exist in the dpkg database. Use a pattern such as dpkg -l 'example*' to find the recorded name. For an uninstalled local archive, use dpkg -I ./package-file.deb.
The Package Has the Wrong Architecture
Inspect the archive with dpkg -I and compare its architecture with the system and intended installation environment. Obtain a package built for the correct architecture rather than forcing an incompatible archive.
APT Cannot Locate a Dependency
Possible causes include stale repository metadata, a disabled repository, an unavailable package, or a package built for another distribution release. Run:
sudo apt update
Then verify enabled repositories and distribution compatibility. Avoid mixing packages from incompatible releases merely to bypass an error.
Configuration Files Remain After Removal
This is expected after dpkg -r. If removing the package configuration is intentional, use:
sudo dpkg -P example-package
Safe Package-Management Practices
- Verify the source and authenticity of a downloaded
.debbefore installing it. - Inspect local package metadata with
dpkg -I, including its architecture and dependencies. - Use exact package names and file paths. Do not confuse a download filename with a package database name.
- Use
sudoor root privileges only for operations that require them. - Read APT's proposed changes before confirming installation, removal, or dependency repair.
- Avoid mixing packages from incompatible Debian or Ubuntu releases.
- Use caution with third-party repositories and packages because they may replace system libraries or introduce unsupported dependency combinations.
- Prefer repository packages when available because APT can keep them updated and resolve their dependencies.
Quick Reference
# Install a local archive with dpkg
sudo dpkg -i ./package-file.deb
# Remove or purge an installed package
sudo dpkg -r package-name
sudo dpkg -P package-name
# List and search package records
dpkg -l
dpkg -l 'package-name*'
# Query installed metadata and package-owned files
dpkg -p package-name
dpkg -L package-name
# Inspect an archive before installation
dpkg -I ./package-file.deb
# Repair dependency problems
sudo apt --fix-broken install
sudo apt-get -f install
# Refresh repositories and install software
sudo apt update
sudo apt install package-name
# Install a local archive through APT
sudo apt install ./package-file.deb
Use this Debian package manager reference when choosing between direct dpkg operations and dependency-aware APT workflows.