HB Computer Security | Aide Memoire
  • Introduction
  • Core Technical Skills
    • Core Skills
      • Linux
        • Getting to Know Linux
          • Using the Shell
            • Shells, Terminals, and Virtual Consoles
            • Choose your Shell
            • Shell Commands
              • Non-PATH Commands
              • Command History
                • Command Line Editing
                  • Keystrokes for Navigating Command Lines
                  • Keystrokes for Editing Command Lines
                  • Keystrokes for Cutting and Pasting Text from within Command Lines
                • Command Line Recall
                  • Keystrokes for Command Line Recall
              • Connecting and Expanding Commands
                • Piping Between Commands
                • Sequential Commands
                • Expanding Commands
            • Shell Variables
              • Common Shell Variables
            • Aliases
            • Create your Own Shell Environment
              • Modification Ideas
          • Navigating the Linux File System (LFS)
            • Filesystem Commands
            • Listing Files and Directories
            • File Permissions and Ownership
              • Modifying Permissions with chmod
              • Modifying Default Permissions with umask
              • Change File Ownership with chown
            • Copying, Moving, and Removing Files
            • Finding Files
              • locate
              • find
              • grep
            • Downloading Files
              • axel
              • wget
              • curl
                • User-Agent: Googlebot
          • Working with Text Files
            • Using vim and vi to Edit Text Files
              • Starting with vi
              • Adding Text
              • Moving Around in the Text
            • Text Manipulation
        • System Administration
          • Installing Linux
            • Installing from Live Media
            • Installing in the Enterprise
            • Partitioning Hard Disks
              • Tips for Creating Partitions
          • Account Administration
            • The root Account
              • Becoming root with su
              • sudo
                • The /etc/sudoers File
                • Granting sudo privileges
                  • visudo Guidance
                • Useful sudo Hints
            • Other Administrative Accounts
            • Standard User Accounts
              • Risks of userdel: Orphaned Files
          • Graphical Remote Administration
            • Cockpit
              • Installation Guide
            • Remote Desktop Protocol with xrdp
              • Installation and Configuration
            • Remote Desktop with vnc
              • Installation and Configuration
              • Running VNC as a System Service
          • Managing Running Processes
            • Listing Processes
              • ps
              • top
              • htop
            • Backgrounding and Foregrounding
              • Starting a Background Process
              • Using Foreground and Background Commands
            • Killing and Recining Processes
              • kill and killall
          • Managing Software
            • Managing Software from the Desktop
            • Going Beyond the Limitations of Software Center
              • Debian Packages
                • Advanced Package Tool (apt)
                • Repositories
                • dpkg
        • Shell Scripting
          • Variables
            • Command Substitution
            • Arguments
          • Reading User Input
          • if, else, and elif
          • BOOLEAN Logic
          • Loops
            • for Loops
            • while Loops
          • Functions
          • Local Vs Global Variables
          • Summary
        • Securing Linux
      • Windows
        • Security Hardening
Powered by GitBook
On this page
  • Installing a .deb File
  • Listing Installed Packages
  • Removing Packages
  • Reconfiguring Packages

Was this helpful?

  1. Core Technical Skills
  2. Core Skills
  3. Linux
  4. System Administration
  5. Managing Software
  6. Going Beyond the Limitations of Software Center
  7. Debian Packages

dpkg

PreviousRepositoriesNextShell Scripting

Last updated 1 year ago

Was this helpful?

Simply put, dpkg is the yin to apt's yang. We use apt for managing software from those big online repositories, leaving dpkg as your go-to when you want to get your hands on packages that are on your local machine.

Let's say you were surfing the web and snagged a .deb package with some software you fancy giving a whirl. If you...

  1. Trust where it came from, and

  2. Are sure it's not been messed with on its way to you...

You can't just use a simple apt install command to put it on your system. Nope, the job of installing, deleting, constructing, and overseeing .deb packages falls squarely on dpkg's shoulders. Let's dive into how it gets the job done.

Installing a .deb File

Installing a .deb file is pretty simple. We use dpkg with the -i option:

sudo dpkg -i package_file_name.deb

Note that in this example, the package is in the same working directory and so the full path is not provided. If you need a quick reminder on relative vs absolute paths,

Listing Installed Packages

Much like we saw with apt, dpkg has the ability to list packages installed on the system:

dpkg -l

This will result in quite a lot of output:

dpkg -l | wc -l

We can also use grep to filter the output if we have a string to work with. Let's presume we want to know if python is installed on the system:

dpkg -l | grep -i python

Interestingly, we see that the output filters on any instance of the string we provide, be it package name or description, so you may need to examine the output carefully to find what you're after. Once you have found your desired package, you can provide its name to dpkg to get more details information:

dpkg -l python3

Removing Packages

Now that we've figured out how to put a package on our system and check out what's already there, it's time to master the art of kicking them out. Here's the deal: packages are found and identified by their dpkg names. Remember how we installed a .deb file earlier? Well, the name we used back then was just the file's name, not the actual package name. So, make sure you follow the steps above to spot the right package you want to say goodbye to.

Removing the package is pretty simple:

sudo dpkg -r package

Reconfiguring Packages

We're almost done with dpkg, but before we move on there is one more feature you should know about. Every so often, for reasons that will become apparent as you gain more experience with Linux, packages can become corrupt. Yes, its super annoying, but dpkg can save us. Once you have found the package name that is corrupt (errors are a clue...) then you can issue the following command to reconfigure the package:

sudo dpkg --configure <package-name>

Pro Tip Many dpkg tasks can also be run through the more user-friendly apt despite the general use cases as described above. A quick google will show you everything you need to know - git it a go!

Remembering what we learned about , we can be a little more creative with this command and generate some useful output. For example, we can leverage the wc (Word Count) command with its -l option to count the amount of lines of output. This will tell us how many packages are installed on the system:

expanding commands and piping
click here
Typical output from dpkg package listing
Amount of packages installed on local system
Filtering dpkg output with grep to find instances of python
Detiled output of an installed package with dpkg