Home >System Tutorial >LINUX >A Beginner's Guide To Using dpkg Command In Linux

A Beginner's Guide To Using dpkg Command In Linux

尊渡假赌尊渡假赌尊渡假赌
尊渡假赌尊渡假赌尊渡假赌Original
2025-03-10 11:22:10925browse

A Beginner's Guide To Using dpkg Command In Linux

This guide provides a foundational understanding of the dpkg command, a core package manager in Debian, Ubuntu, and related Linux distributions. We'll cover essential uses, including installation, removal, and package management tasks.

What is dpkg?

dpkg (Debian Package) is a command-line utility for managing individual .deb packages. While powerful, it's a mid-level tool; it doesn't automatically handle dependencies. For dependency management, higher-level tools like apt are recommended.

Basic Syntax

The basic dpkg command structure is:

dpkg [options] action

Common Actions and Options:

The table below summarizes common dpkg actions and useful options:

Action Description Example
-i, --install Installs a
Action Description Example
-i, --install Installs a .deb package. sudo dpkg -i package.deb
-r, --remove Removes a package (configuration files remain). sudo dpkg -r package_name
-P, --purge Removes a package and its configuration files. sudo dpkg -P package_name
-l, --list Lists installed packages (optional: filter with grep). dpkg -l, dpkg -l | grep firefox
-L, --listfiles Lists files installed by a package. dpkg -L package_name
-S, --search Finds the package a file belongs to. dpkg -S /path/to/file
-s, --status Shows detailed package status. dpkg -s package_name
-b, --build Builds a .deb package from a directory. dpkg -b directory
--configure Configures an unpacked but unconfigured package. dpkg --configure package_name
--unpack Unpacks a .deb package without configuring it. dpkg --unpack package.deb
--no-act Simulates the command without making changes. dpkg --no-act -i package.deb
package.
sudo dpkg -i package.deb
-r, --remove Removes a package (configuration files remain). sudo dpkg -r package_name
-P, --purge Removes a package and its configuration files. sudo dpkg -P package_name
-l, --list Lists installed packages (optional: filter with grep). dpkg -l, dpkg -l | grep firefox
-L, --listfiles Lists files installed by a package. dpkg -L package_name
-S, --search Finds the package a file belongs to. dpkg -S /path/to/file
-s, --status Shows detailed package status. dpkg -s package_name
-b, --build Builds a package from a directory. dpkg -b directory
--configure Configures an unpacked but unconfigured package. dpkg --configure package_name
--unpack Unpacks a package without configuring it. dpkg --unpack package.deb
--no-act Simulates the command without making changes. dpkg --no-act -i package.deb

Common Use Cases

Let's illustrate with practical examples:

  1. Installing a Package:

    dpkg [options] action
  2. Removing a Package:

    sudo dpkg -i google-chrome-stable_current_amd64.deb 
  3. Purging a Package:

    sudo dpkg -r firefox-esr
  4. Listing Installed Packages:

    sudo dpkg -P linux-image-5.10.0-11-amd64
  5. Listing Files of a Package:

    dpkg -l | grep -i chrome
  6. Finding a File's Package:

    dpkg -L google-chrome-stable
  7. Showing Package Status:

    dpkg -S /bin/uname

Conclusion

dpkg is a fundamental tool for managing Debian packages. While powerful for individual package manipulation, remember to use apt or apt-get for dependency handling to avoid potential system instability. For comprehensive information, consult the dpkg manual page (man dpkg). Using apt or apt-get is generally recommended for everyday package management tasks.

The above is the detailed content of A Beginner's Guide To Using dpkg Command In Linux. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn