How To Uninstall a Deb File Installed With Dpkg

Debian Linux distribution and its variants, such as Ubuntu, use deb files to install or update Unix applications. There are many ways to install them on your device, one of which is using the dpkg command. How about uninstalling the .deb package? Can dpkg uninstall it? Indeed, this command can do that.

This article will let you know more about this command and how to remove .deb files with dpkg.

What Is the dpkg Command?

The dpkg command is a powerful package management tool used in Debian-based Linux distributions such as Ubuntu, Debian, and Linux Mint. It is used to install, remove, and manage packages on a system.

The dpkg command has many uses, including but not limited to the following:

  • Install a package from a .deb file
  • Remove a package from the system
  • List all installed packages on the system
  • Find the package that owns a specific file
  • Reconfigure an already installed package
  • List all the files installed by a package
  • Show information about a package, such as version number and description

Dpkg Basics

The first thing you need to learn about this command is the basic syntax.

The syntax is:
dpkg [options] [.deb package name]

Replace the [.deb package name] with the package name you want to modify with the dpkg command. Then, remove the brackets.

Suppose you are installing Teamviewer with this command. The code will be:
sudo dpkg -i teamviewer_15.7.6_amd64.deb

As you can see, we used "-i" for the option. This installs the package. The other options are:

  • -r OR --R: removes every file belonging to the specific package except the configuration files, also known as the uninstallation process.
  • -p OR --purge: this is the complete uninstallation option. It removes every file belonging to the specific package, including the configuration files.
  • --update-avail: checks the online repositories. Then, it downloads all the updated packages to your local repository.
  • --update-merge: combines information about available packages in its repositories with previously available information. You typically run this after updating the repositories.
  • s package_name: shows information about a package, such as version number and description
  • -S file_name: finds the package that owns a specific file.
  • -l package_name: lists all installed packages on the system
  • -L package_name: lists all the files installed by a package.
  • -reconfigure package_name: reconfigures an already installed package

Remove a .deb Installed With dpkg Using dpkg -r

As mentioned above, you can use the -r or --remove options to uninstall packages from your Linux device.

The sudo dpkg -r command is used to remove a package from a Debian-based Linux system using dpkg, the Debian package management tool. The -r option specifies that you want to remove the package.

To use this command, you need to have administrative privileges on the system, hence the use of sudo. You will also need to specify the name of the package you want to remove after the dpkg -r command.

For example, if you want to remove the package named "demo," you would run the following command:
sudo dpkg -r demo

This command will remove the "example" package from your system. If the package has any dependencies that are no longer needed, they will also be removed.

Note that using the dpkg -r command only removes the package files from the system; it does not remove any configuration files associated with the package. To remove both the package and its configuration files, you can use the dpkg -P (purge) option instead of -r.

For example:
sudo dpkg -P demo

This command will remove the "demo" package and its associated configuration files from your system.

How To Recover Accidentally Deleted Deb File in Linux

Perhaps you deleted the wrong files. Or you attempted to uninstall a .deb file without learning how to do it properly first. As a result, you have lost files that aren't supposed to be deleted.

Don't fret. You can recover the lost files. Tools like Wondershare Recoverit can help you retrieve those that you have accidentally deleted.

Wondershare Recoverit - Your Safe and Reliable Linux Recovery Software

5,481,435 people have downloaded it.

Recovers lost or deleted documents, photos, videos, music, emails, and other 1000+ file types effectively, safely, and completely.

Compatible with all mainstream Linux distros, including Ubuntu, Linux Mint, Debian, Fedora, Solus, Opensuse, Manjaro, etc.

Assists in 500+ data loss scenarios, such as deletion, disk formatting, OS crash, power outage, virus attack, lost partition, and many more.

The simple point-and-click interface allows you to recover data from Linux hard drives in just a few clicks.

Works through a remote connection. You can recover lost data even when your Linux device is crashed.

Without further ado, here's how to recover lost files using Recoverit's Linux File Recovery feature.

Step 1Choose Linux Recovery

Download Wondershare Recoverit and install it. Launch the application, then select NAS and Linux on the lefthand panel. Click Linux Recovery on the righthand panel to proceed.

nas and linux window on wondershare recoverit
Step 2Connect to the Linux Computer

To recover data from Linux, you need to create a remote connection between the program and your Linux computer. Click the Connect button once you are done filling out the necessary details.

establishing remote connection to linux device

Please wait for the connection to be successfully established. After that, Wondershare Recoverit will automatically start the scanning process. It will look for lost files in your Linux computer.

scan deleted or lost data in linux
Step 3Preview and Recover Deleted Files

The scanning process takes seconds to minutes depending on the amount of data to be scanned. You can stop the scanning whenever you see the files you want to recover. Recoverit allows you to preview the files it found. With this, you can verify that it is the file that you want. After doing so, select the desired files and click the Recover button to save them.

checking the file found by recoverit
Free Download

For Windows Vista/7/8/10/11

Free Download

For macOS X 10.10 or later

Note that the success of the recovery process largely depends on different factors. The state of the deleted files and the duration between when they were deleted and when you attempted to recover them matters. Likewise, the amount of disk activity that occurred after the files were deleted can affect the process.

Therefore, you should attempt the recovery process as soon as possible after the files are deleted. Plus, avoid making any further changes to the disk or partition where the deleted files were located until the recovery process is completed.

FAQs

Yes, you can use Ubuntu to install Debian packages using the dpkg command-line tool. However, it's important to exercise caution as some Debian packages may not be fully compatible with Ubuntu and may cause issues or conflicts.

You can place .deb files anywhere on your Ubuntu system, but it's recommended to place them in your home directory or a dedicated folder for easy access. You can then use the dpkg command-line tool to install the packages.

Yes, Ubuntu uses apt-get as its default command-line package management tool. It is used to manage and install software packages on Ubuntu and other Debian-based Linux distributions and is part of the Advanced Packaging Tool (APT) suite.

The syntax for extracting the contents of a .deb file is:
dpkg-deb -x [name of the .deb file.]
For example:
dpkg-deb -x example.deb /path/to/extract/
It will extract the contents of example.deb to /path/to/extract/.

dpkg is a low-level tool used to manage individual .deb packages. Meanwhile, aptitude is a higher-level tool that can handle package dependencies, interact with multiple sources, and install or remove packages with a single command. dpkg is a component of apt, while aptitude is an advanced front-end to apt.

Summing Up

You can install and uninstall .deb packages using the dpkg commands. Use the -i option to install and the -P or -r options to uninstall. If you accidentally removed the wrong files, you can use Wondershare Recoverit to recover the deleted files.

You May Also Like

Best Alternatives to Recuva for Linux

This article introduces Recuva and its limitations while offering its best alternatives.

How To Undelete Files Using debugfs in Linux

A guide to recover deleted files using debugfs - a Linux interactive file system debugger.

How To Recover Data From LVM Partitions on Linux

Learn step-by-step procedures to restore data from LVM partitions on Linux systems.

How To Undo rm in Linux

What can you do to protect Linux data from the accidental running of the RM command?