5 Methods to Remove Package and Dependencies in Ubuntu

LINUX
FUNDAMENTALS
A Complete Guide for Beginners Enroll Course Now

Dependencies specify some prerequisite packages that are essential for a particular package to work as intended. Often, you may not be using an installed package because you don’t need it anymore. Besides, sometimes you may need to install a package to do a one-time task or solve a specific problem. In these cases, you can remove the package to free your system memory. In this tutorial, I’ll demonstrate different ways that you can use to remove packages and dependencies in Ubuntu distributions.

To remove packages and unused dependencies, check the following methods:

  1. Using apt or apt-get command: apt autoremove <package_name>
  2. Using snap command: snap remove [package_name]
  3. Using dpkg command: dpkg -r <package_name>
  4. Using synaptic package manager
  5. Using GNOME software

Key Takeaways

  • Removing the DEB package in Ubuntu.
  • Inspecting dependencies regarding TeamViewer and VLC uninstallation.
  • Uninstalling unused dependencies during the removal.

Requirements

Process Flow Chart

[Distro Used Throughout the Tutorial: Ubuntu 22.04.1 LTS]5 methods to remove package and dependencies in ubuntu

5 Methods to Remove Packages and Dependencies in Ubuntu

In Linux, you can remove a package in two basic types. The first one is to remove a package with all its dependencies like config files, libraries, and binaries using CLI. Secondly, you can remove a package using the package manager in GUI.  In this guide, I’ll show you five different approaches you can use in both cases in your Ubuntu system.

You can read our Comparative Analysis of Methods to distinguish between these five methods and pick the best one for your needs.

A. Remove Packages and Dependencies in Ubuntu With CLI

CLI(Command Line Interface) is a command line tool for Linux where you can type and execute commands directly. To remove a package and its dependencies using CLI, built-in package management tools are used. In the first three methods, I’ll show you the use of different package management tools in CLI to remove a package and dependencies in Ubuntu.

Method 01: Using “apt” or “apt-get” to Remove Packages and Dependencies

APT (Advanced Package Tool) is a powerful package management system used in Debian-based Linux distributions, including Ubuntu. It simplifies software removal as well as installation by handling dependencies automatically.

To remove an unused package with all dependencies, APT offers the following syntax:

sudo apt autoremove <package name>
EXPLANATION
  • sudo: Enables administrative permissions.
  • apt: Calls APT package management tools.
  • autoremove: Removes all dependencies that were installed during the installation of the package.
  • <package name>: Name of the package you want to remove.

Now, follow these steps to remove TeamViewer with all dependencies using APT:

Steps to Follow >

➊ Open the Ubuntu terminal. You can press CTRL+ALT+T.

➋ Run the following command:

sudo apt autoremove teamviewer

➌ Enter user password if required.

➍ Type Y when the confirmation prompt appears.

➎ Press ENTER.removing teamviewer with dependencies by aptBy the above command, APT will remove TeamViewer from the system with all unused dependencies. However, you can also use the apt-get command to remove packages and dependencies using the following syntax:

sudo apt-get autoremove <package name>

These commands removes dependencies but keeps the configuration files. However, if you want to remove the configuration files also, you have to use the below command:

sudo apt autoremove --purge <package name>
Note: Replace <package name> in the command with the actual name of the package.

Method 02: Using “snap” to Remove Package and Dependencies

Snaps in Ubuntu are designed to be self-contained and don’t have explicit dependencies on other packages like traditional package management systems such as APT. This means that when you remove a snap package, it should not affect other parts of your system, and there are no dependencies to manage. Anyway, to remove a snap package and its associated dependencies which are contained within the snap package itself, you can follow the below steps:

Steps to Follow >

➊ Open the Ubuntu terminal.

➋ Run the below command to list all snap packages installed in the system:

snap list
EXPLANATION
  • snap: Command to manage Snap packages.
  • list: Displays a summary of snaps installed in the current system.
Listing snap packagesThe above command shows a list all the snaps installed in the system. Let’s say, you chose vlc to remove.

➌ Run this command to remove vlc snap:

snap remove vlc
EXPLANATION
  • remove: Command to remove Snap packages.
  • vlc: Snap package name that you want to remove.

➍ Enter user password in the authentication box.

➎ Click on Authenticate.Entering user password to authenticate snapAfter that, some quick message will be shown in the terminal. Finally, the terminal will show a confirmation message of removal like this:VLC snap removal is successfulThis indicates that the removal of vlc snap is successful.

Method 03: Using “dpkg” to Remove Package and Dependencies

DPKG (Debian Package Manager) is a low-level package manager in Debian-based Linux distributions that provides dpkg package management tool. Like installing, this tool can also remove packages from Ubuntu. Becoming a flexible package management tool, dpkg provides the facility to remove packages with some selective dependency packages. So, if you have the .deb file of the package you want to remove with dependencies, you can use dpkg by following these steps:

Steps to Follow >

➊ Open the Ubuntu terminal.

➋ Change the working directory to where the .deb file is present. In my case, it is in the Downloads folder.

cd ~/Downloads/
EXPLANATION

➌ Check the file presence using this command:

ls
EXPLANATION
  • ls: Lists all the files and folders in the current directory.
viewing the contents of download folder➍ Run the following command to see dependency packages:

sudo dpkg -I teamviewer_15.43.7_amd64.deb | grep Depends | sed 's/Depends: //' | tr ',' '\n' | sed 's/^ *//'
EXPLANATION
  • sudo: Enables administrative permissions.
  • dpkg: Calls DPKG package manager.
  • -I: Option is used to display information about the package
  • grep: Command to search lines in the output.
  • | (Piping Symbol): Used to transfer the output of a command as the input of another command.
  • sed ‘s/Depends: //’: Here, the sed command is used to remove the “Depends: ” prefix from each line that contains the word “Depends.
  • tr ‘,’ ‘\n’: This command replaces commas (,) with newline characters (\n).
  • sed ‘s/^ *//’: This sed command removes any leading spaces of each line.
dependency of teamviewer listed by dpkg
Note: If you don’t have the .deb file or don’t know the directory where it is, you can use this command from any directory to list the dependencies:

apt show <package name>| grep Depends | sed 's/Depends: //' | tr ',' '\n'  | sed 's/^ *//'

Replace <package name> with the actual name of the package you want to remove.

The output shows all dependencies of TeamViewer in a list. You can manually select which dependencies you want to remove with TeamViewer. Suppose, I want to remove libminizip1 along with TeamViewer. Follow the next step to do that.

➎ Write the following command on the terminal:

sudo dpkg -r teamviewer libminizip1
Warning: Be careful when manually removing a dependency as it may hamper other package that uses the dependency.

➏ Enter the user password if asked.

➐ Press ENTER.Removing libminizip1 by dpkg

Note: If you want to remove more dependencies, write them separated by SPACE in the above command. 

➑ After removing dependencies, you can remove the software package with the same syntax:

sudo dpkg -r <package name>

In this case, <package name> will be replaced with teamviewer.

B. Remove Packages and Dependencies in Ubuntu With GUI

In Ubuntu, you can manage software packages using GUI (Graphical User Interface) tools. The most commonly used GUI package management tools are:

  • Synaptic Package Manager
  • Ubuntu GNOME Software

Now in the following two methods, I’ll show you how to use these tools of GUI package management to remove a package and dependencies in Ubuntu.

Method 04: Using Synaptic Package Manager to Remove Package and Dependencies in Ubuntu

Synaptic Package Manager, often called “Synaptic“, is a GUI (Graphical User Interface) package management tool for Debian-based Linux distributions. It can handle dependencies and other package management tasks such as installing, removing and updating packages effectively. Follow these steps to remove packages and dependencies using Synaptic in Ubuntu:

Steps to Follow >

➊ Open Synaptic Package Manager from the Show Applications section.Opening synaptic package manager from show application section➋ Type the user password in the authentication window and click Authenticate.Entering user password to authenticate synaptic package manager➌ Click on the Search icon at the top right corner.

➍ Type teamviewer in the search box.

➎ Click on Search.searching for teamviewer in synaptic package managerA list of packages that have “teamviewer” in their name will appear.

Right-click on the package and select Mark for Complete Removal.Selecting mark for complete removalAfter that, Synaptic Package Manager will remove TeamViewer completely from the system.

Method 05: Using Ubuntu Software to Remove Package and Dependencies in Ubuntu

Ubuntu Software Center, also known as GNOME Software, provides a graphical interface for installing and removing software on Ubuntu. When you use it to uninstall a software package, it will typically handle the removal of any dependencies that were automatically installed alongside the package. Here’s how to do it:

Steps to Follow >

➊ Open the Ubuntu terminal.

➋ Run this command:

gnome-software

➌ Press ENTER.

➍ Click on Installed.Navigating to installed section in GNOME software➎ Scroll down to the package you want to remove and click Uninstall.Clicking on uninstall button of VLCThen, GNOME-Software will remove VLC and its dependencies from your Ubuntu.

Comparative Analysis of Methods

I’ve shown a total of five ways to remove packages and dependencies in Ubuntu. You might be confused to decide which one suits you the best. Here’s a comparison between the methods provided to give you an overview of the pros and cons.

Methods Pros Cons
Method 1
  • Automatically identifies and removes all dependencies.
  • Convenient syntax that doesn’t depend on the present working directory.
  • Shows progress bar of removal.
  • Allows to remove configuration files.
  • Doesn’t support selective removal of dependency package.
Method 2
  • Enables to use the latest version of software in older version distribution.
  • No dependency conflict due to non-shared module.
  • Occupies extra space because of binding separate copies of shared modules.
  • It’s a different type of package and so, not all software is found in Snap.
Method 3
  • Provides manual inspection on dependency packages.
  • Can remove dependency packages selectively which helps developers.
  • Can be unuseful for regular users while removing all dependencies of a package with many dependencies.
  • Needs to be careful about breaking other packages.
Method 4
  • Automatically identifies all installed dependencies and removes them.
  • Provides a user-friendly GUI that is suitable for beginners.
  • Hides internal complexity from the user.
  • May take more time compared to other methods.
  • Don’t show any progress bar.
Method 5
  • Automatically removes all dependencies along with a package.
  • Easy to find installed software and just one click away to remove that.
  • Automatically prevents and manages dependency conflict.
  • Only works for packages those were installed via Ubuntu Software.

If you are comfortable with CLI and want to remove a package and all its dependencies automatically, you can use “Method 1″. However, if you are not comfortable with CLI, you can use “Method 4″ in this situation. In case, you have a .deb file of a package and you want to remove it and its dependencies, you should follow “Method 3″. Moreover, use “Method 2″ to remove a Snap package. “Method 5″ is suitable for removing a package that was installed via Ubuntu Software.

Common Challenges That May Arise

Although some of the package managers handle missing dependencies in Ubuntu automatically, challenges may arise sometimes. Some common challenges you might encounter and how to address them are listed below.

  • Unintended Removal: Be cautious when using commands like apt autoremove or apt remove with packages that have a large number of dependencies.
  • Configuration Files: Removing configuration files with apt remove are often retained by default. If you want to remove them, you need to use apt purge or apt –purge remove.
  • Dependency Conflicts: Sometimes, removing a package can result in dependency conflicts if multiple packages share the same dependencies.
  • Dependencies Marked as Manually Installed: Packages installed as dependencies are marked as “automatically installed” by default. Using apt autoremove can remove these automatically installed packages, it can lead to the removal of packages you might still need.
  • System Unstable: If you’re unsure about the consequences of removing a package and its dependencies, this may lead to an unstable system.

Install GNOME Software in Ubuntu

If you don’t have GNOME Software installed, first you have to install it to use. To install GNOME Software in your Ubuntu, follow the below steps:

Steps to Follow >

➊ Open the Ubuntu terminal.

➋ Run this command:

sudo apt install -y gnome-software
EXPLANATION
  • sudo: Enables administrative permissions.
  • apt: Calls APT package management tools.
  • install: Command for installing a package using apt.
  • -y: Answers YES automatically to any confirmation prompt.
  • gnome-software: Package name of GNOME software.

➌ Enter the user password if asked.

➍ Press ENTER.Installing gnome-software by aptThat’s it. Now apt will install GNOME Software in your Ubuntu.

Conclusion

To minimize the challenges regarding dependency removal, it’s crucial to carefully review the consequences before proceeding with any removal operation. Understanding the dependencies and potential impacts on your system is key to the successful removal of packages and dependencies  in Ubuntu. It’s better to use a virtual environment before removing crucial packages that may be used by the system itself.

People Also Ask

How do I uninstall a package and dependencies in Ubuntu?
You can use the Software Center to easily uninstall packages on Ubuntu. Open it, go to the Installed tab, find the application, and click Uninstall. Additionally, you can use this command in the terminal to remove packages: sudo apt-get remove -y <package name>.
How to remove package with dependencies in Linux?
To remove a package with dependencies, use this command: sudo apt autoremove <package name>. Replace <package name> in the command with the actual name of the package you want to remove.
How do I remove apt package and dependencies?
APT is a package manager used in Debian-based Linux distros. To remove packages and dependencies using APT, run this command from the terminal: sudo apt autoremove <package name>. Replace <package name> in the command with the actual name of the package you want to remove.
Does apt remove dependencies?
Yes, APT is a high-level package management tool that can automatically remove dependencies while removing a package by the command: sudo apt autoremove <package name>. You have to replace <package name> in the command with the actual name of the package you want to remove.

Related Articles


<< Go Back to Dependencies in Linux | Package Management in Linux | Learn Linux Basics

5/5 - (10 votes)
Ashikur Rahman

Hello, I’m Ashikur Rahman, currently working as a Linux Content Developer Executive at SOFTEKO. I have completed my graduation in Computer Science and Engineering from Khulna University of Engineering & Technology (KUET). Also, I’m pursuing my master’s in the same department at Bangladesh University of Engineering & Technology (BUET). I like to learn new technologies, contribute, and share those with others. Here my goal is to provide beneficial and user-friendly articles on Linux distribution for everyone. Read Full Bio

Leave a Comment