GO KALI FREE
BeginnerLinux

Linux Package Management: APT, DPKG, and Beyond

Master Linux package management across Debian-based systems including APT, DPKG, repository configuration, dependency resolution, and troubleshooting.

#package management#APT#DPKG#Linux#software installation

Managing Software on Linux

Every security tool on Kali Linux — from Nmap to Metasploit — is installed through the package management system. Knowing how to install, update, and troubleshoot packages is a core operational skill that you will use daily. This guide covers APT, DPKG, and related tools so you can keep your environment up to date and resolve dependency issues without breaking your system.

Prerequisites

Familiarity with basic Linux commands and terminal navigation. Root or sudo access for package operations.

DPKG — The Foundation

DPKG is the low-level tool that directly installs, removes, and queries .deb packages.

Basic DPKG Commands

sudo dpkg -i package.deb          # Install a .deb file
sudo dpkg -r package_name         # Remove a package (keep configs)
sudo dpkg -P package_name         # Purge a package (remove everything)
dpkg -l                           # List installed packages
dpkg -L package_name              # List files installed by a package
dpkg -S /path/to/file             # Find which package owns a file

DPKG Troubleshooting

sudo apt --fix-broken install    # Fix missing dependencies

APT — The Package Manager

APT works with DPKG to provide dependency resolution, repository management, and a user-friendly interface.

Repository Configuration

APT works with sources in /etc/apt/sources.list:

deb http://http.kali.org/kali kali-rolling main non-free contrib

Essential APT Commands

sudo apt update                    # Update package index
sudo apt upgrade                   # Upgrade all packages
sudo apt full-upgrade              # Full upgrade with dependency changes
sudo apt install nmap              # Install a package
sudo apt remove nmap               # Remove a package
sudo apt purge nmap                # Purge a package and configs
apt search "web scanner"           # Search for packages
apt show nmap                      # Show package information
apt list --installed               # List installed packages
sudo apt autoremove                # Remove unneeded packages
sudo apt clean                     # Clear package cache

APT Update Pipeline

  • `apt update` — Downloads package indexes
  • `apt list --upgradable` — Shows available updates
  • `apt upgrade` — Upgrades packages
  • `apt full-upgrade` — Handles changing dependencies
  • Dependency Resolution

    apt install --dry-run wireshark    # Simulate install without changes
    

    Adding Third-Party Repositories

    # Method 1: add-apt-repository
    sudo apt install software-properties-common
    sudo add-apt-repository ppa:deadsnakes/ppa
    
    # Method 2: Manual repository file
    curl -fsSL https://download.docker.com/linux/debian/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker.gpg
    echo "deb [arch=amd64 signed-by=/usr/share/keyrings/docker.gpg] https://download.docker.com/linux/debian bookworm stable" | sudo tee /etc/apt/sources.list.d/docker.list
    
    # Method 3: Direct .deb download
    wget https://example.com/software.deb
    sudo dpkg -i software.deb
    sudo apt --fix-broken install
    

    Package Hold and Pinning

    sudo apt-mark hold package_name     # Prevent package from being upgraded
    sudo apt-mark unhold package_name   # Unhold a package
    apt-mark showhold                   # Show held packages
    

    Real-World Examples

    Installing Metasploit: sudo apt install metasploit-framework

    Minimal install: sudo apt install --no-install-recommends package

    Upgrading Kali: sudo apt update && sudo apt full-upgrade -y

    Common Mistakes

    Running apt upgrade without apt update first. Using unstable repos without pinning. Forgetting GPG keys for third-party repos.

    Best Practices

    Always run sudo apt update before sudo apt upgrade. Use apt search and apt show before installing. Use --dry-run to preview changes. Remove unused packages with sudo apt autoremove. Verify GPG keys when adding repositories.

    Related Tools

    snap — Canonical's container package system. flatpak — Sandboxed applications. gdebi — GUI .deb installer. aptitude — Alternative APT interface.

    Related Articles

  • kali-linux-beginner-guide
  • linux-commands-explained
  • command-line-essentials
  • linux-terminal-guide
  • kali-linux-virtualbox
  • Summary

    Package management on Debian systems uses DPKG (low-level .deb handling) and APT (high-level dependency resolution). Essential commands: apt update,apt install, apt upgrade, apt remove. Understanding both tools is fundamental to maintaining a healthy Linux system.

    Knowledge Check

  • What is the difference between DPKG and APT?
  • What command updates the package index?
  • How do you search for packages with APT?
  • What does `sudo apt --fix-broken install` do?
  • Where are downloaded package files cached?
  • Frequently Asked Questions

    What is the difference between apt and dpkg?

    DPKG is the low-level tool that directly installs, removes, and queries .deb packages but cannot handle dependencies. APT is the high-level manager that works with DPKG to resolve dependencies, manage repositories, and provide a user-friendly interface. Always prefer APT commands for daily use.

    Why should I run apt update before apt upgrade?

    apt update downloads the latest package index from repositories, listing available versions. Running apt upgrade without updating first upgrades to whatever versions your local index knows about, which may be outdated. Always run `sudo apt update && sudo apt upgrade` together.

    How do I fix broken package dependencies?

    Run `sudo apt --fix-broken install` to resolve missing or conflicting dependencies. This commonly happens when installing .deb files with dpkg that have unmet dependencies. APT will automatically download and install the missing packages to complete the dependency chain.

    How do I search for a package before installing it?

    Use `apt search keyword` to find packages matching a term, or `apt show package-name` to view detailed information including version, size, dependencies, and description. Use `apt list --installed` to check if a package is already installed on your system.

    What does apt purge do that apt remove doesn't?

    apt remove uninstalls a package but keeps configuration files in /etc. apt purge removes both the package AND its configuration files. Use purge when you want a completely clean removal, and remove when you might want to reinstall later with the same settings.

    How do I add a third-party repository to APT?

    Import the GPG key with `curl -fsSL URL | sudo gpg --dearmor -o /usr/share/keyrings/key.gpg`, then add the repo line to /etc/apt/sources.list.d/ with `signed-by=/usr/share/keyrings/key.gpg`. Run `sudo apt update` afterward. For PPAs, use `sudo add-apt-repository ppa:name`.

    What is apt-mark hold and when should I use it?

    apt-mark hold prevents a specific package from being upgraded during apt upgrade. Use it when a newer version breaks compatibility with your tools, or when testing a specific version. Release it with `apt-mark unhold package-name` once you're ready to upgrade.

    How do I install a local .deb file?

    Use `sudo dpkg -i package.deb` for the local file, then `sudo apt --fix-broken install` to resolve any missing dependencies. Alternatively, `sudo apt install ./package.deb` handles both installation and dependency resolution in one step. See our [Linux commands guide](/learn/linux-commands-explained) for more.

    How do I clean up disk space used by APT?

    Run `sudo apt clean` to remove downloaded .deb files from the cache, and `sudo apt autoremove` to remove packages installed as dependencies that are no longer needed. Together, these commands can free significant disk space on systems with many installed packages.

    What are the different APT upgrade commands?

    apt upgrade upgrades packages without removing any. apt full-upgrade can remove packages if needed to resolve dependency changes. apt dist-upgrade is the older equivalent of full-upgrade. Use full-upgrade for Kali Linux rolling releases where dependencies frequently change.

    How do I hold back a package from upgrading?

    Use `sudo apt-mark hold package-name` to prevent a package from being upgraded. Check held packages with `apt-mark showhold`. This is useful when a newer version breaks your workflow or when pinning a specific version for compatibility. Release with `sudo apt-mark unhold package-name`.