Home >System Tutorial >LINUX >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
|
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:
Installing a Package:
dpkg [options] action
Removing a Package:
sudo dpkg -i google-chrome-stable_current_amd64.deb
Purging a Package:
sudo dpkg -r firefox-esr
Listing Installed Packages:
sudo dpkg -P linux-image-5.10.0-11-amd64
Listing Files of a Package:
dpkg -l | grep -i chrome
Finding a File's Package:
dpkg -L google-chrome-stable
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!