Jun 4, 2024 14 min read

How to Remove Packages From Ubuntu via Command Line

Remove Packages From Ubuntu via Command Line with our step-by-step tutorial. Ubuntu uses packages for streamlined software management.

Remove Packages From Ubuntu via Command Line
Remove Packages From Ubuntu via Command Line
Table of Contents

Introduction

Before we begin talking about how to remove packages from Ubuntu via command line, let's briefly understand – What is Ubuntu and Packages?

Ubuntu is a popular, user-friendly operating system based on Linux. It provides a free and open-source alternative to Windows and macOS. Ubuntu uses "packages" to install, update, and manage software applications. These packages contain all the necessary files and instructions for installing programs seamlessly on your system.

By using Ubuntu and its packages, you can easily access and enjoy a wide range of software tools and utilities tailored to your needs. Upgrade your computing experience with Ubuntu and explore a world of diverse applications through its simple package management system.

In this tutorial, you will remove packages from Ubuntu via command line. We will also address a few FAQs on how to remove packages from Ubuntu via command line.

Methods for Installing Ubuntu Software Packages

Ubuntu's software center offers quick access to a wide selection of applications. Users can also install packages with the apt utility, apt-get command, or terminal.

Method 1: Using the Ubuntu Software Center

Using Ubuntu Software Center to install packages is one of the easiest ways to do it. You can browse and search the official Ubuntu repositories for packages with this graphical tool. To access the Ubuntu Software Center, just take these simple actions:

  1. From the Applications menu, select the Ubuntu Software Center to open.
  2. To find the software package you wish to install, use the search field.
  3. Choose the bundle from the list of results.
  4. Press the Install button.

The package and any dependencies it needs will be downloaded and installed by the Ubuntu Software Center, which will take care of the rest. One of the simplest methods for uninstalling apps in Ubuntu is this one.

Method 2: Using the apt Command

You can interact with the Ubuntu package repositories straight from the command line by using the apt command, a potent package management tool. The following are the standard commands for installing packages using apt:

  • sudo apt update — Add the most recent data from the repositories to the local package index.
  • sudo apt install [package] — Install a new package.
  • sudo apt remove [package] — Uninstall a package.
  • sudo apt upgrade — Upgrade all packages to their latest available versions.
  • sudo apt autoremove — Remove all dependencies that were installed automatically and are no longer needed.

Here's an example of how to use the apt command to install a package:

sudo apt update

sudo apt install apache2

The commands in the example above will install the Apache web server package and update the local package index.

Method 3: Using a PPA (Personal Package Archive)

An individual or group that builds and hosts a collection of Ubuntu binary packages is known as a PPA, or personal package archive. Packages that are under development and not yet included in the official repositories may be found in PPAs, as well as packages that are not present in the official Ubuntu repositories.

Prior to using a PPA, add it to your system by doing the following steps:

  1. Locate the PPA you wish to utilize.
  2. To save the PPA URL to your clipboard, copy it.
  3. Launch a terminal window, then enter the following command, changing [ppa-url] to the URL you copied earlier.
sudo add-apt-repository [ppa-url]

4. When prompted, enter your password.

5. Update the local package index with the most recent data from the new PPA by using the command below:

sudo apt update

Method for Finding Installed Software on Ubuntu

Using the terminal is one of the best and most straightforward ways to find installed software on Ubuntu. To use the command line to look for installed applications, follow the instructions below.

Step 1: Open a Terminal Session

You can open the terminal window from the applications menu or by using the keyboard shortcut Ctrl + Alt + T.

Step 2: Run dpkg Command

You can use the dpkg command to discover details about installed packages. Press the Enter key after typing the following command to see a list of installed applications:

sudo dpkg --list

Using the above command, your Ubuntu system's installed packages will be listed.

Step 3: Search for Installed Software

Use this command to look for a specific installed program:

sudo dpkg --list | grep <software_name>

For example, use the following command to determine the installed version of the Firefox web browser:

sudo dpkg --list | grep firefox

More Information on Listing All Installed Software Packages on Linux

Are you wondering how to remove a program from Linux?

In Linux, you can find out the precise package names if you know roughly what you want to uninstall but not its name. Recall that you can view a list of all installed packages on your computer by using the apt or dpkg commands. To open a terminal window, press Ctrl + Alt + T. At the prompt, enter the following command and hit the Enter key:

sudo apt list --installed
sudo apt-cache search <package_name> 

Or:

sudo dpkg --list

Locate the package you wish to uninstall by scrolling through the terminal window's list of installed packages. Make a note of the package's entire name. Next, enter one of the subsequent commands:

sudo apt remove <package_name> 
sudo apt remove <package_name_1> <package_name_2>
sudoapt purge <package_name> 

These commands are helpful in certain circumstances. For further information, refer to the sections below:

sudo apt-get clean

The aptitude cache that is kept in /var/cache/apt/archives is deleted with this command. The package file is downloaded and placed in that directory when you install a program. The data in that directory is not required to be kept there. The only downside to removing that data is that you would need to download the packages again if you ever wanted to reinstall any of those programs.

Primary Methods for Uninstalling Software

Various commands are used by different operating systems to carry out actions. On Ubuntu, the apt command is usually the best way to interact with the packages. Installing and removing software is the main purpose of the apt command on Ubuntu systems. There are two options available to the user:

  • apt-get purge
  • apt-get remove

This apt-get command is used multiple times in the Ubuntu software uninstalling instructions that follow. Let's examine how to remove apps in Ubuntu.

Method 1: Using the apt-get purge Command for Ubuntu Uninstalls

Ubuntu packages (unnecessary packages, including configuration files, listed directories, and files) can be removed with the apt-get purge command. It completely removes the software from the computer.

Before executing this command, make sure you have a backup of any necessary files (example shown below). To purge a package, you can use the following command, replacing <package_name> with the desired package:

sudo apt-get purge <package_name>

Method 2: Using the apt-get remove Command for Ubuntu Uninstalls

Ubuntu packages can be removed with the apt-get remove command, but configuration files and other dependencies are left behind. It eliminates the package along with all of its essential parts. View the example of the command below. To remove a package, run the following command and replace <package_name> with the desired package:

sudo apt-get remove <package_name>

Method 3: Using the apt-get –f install or apt-get --fix-broken install Command to Fix Software Packages

This option examines the installed apps using the -f or --fix-broken flags option, and it will try to fix any broken packages it finds. These options fix any package dependencies that were unintentionally removed and fix broken packages. Utilizing these choices will search the whole system for damaged or absent packages. Take a look at the commands below:

sudo apt-get –f install

These flags do not remove any packages; they only replace broken packages that are found. They will try to fix a system that has malfunctioning dependencies. When combined with install/remove, this option allows apt to determine a likely solution by leaving out any packages. Should packages be specified, they must fix the issue entirely:

sudo apt-get --fix-broken install

Method 4: Using the apt-get autoremove Command to Remove Ubuntu Software Package Dependencies

The apt-get command may leave behind other dependencies that were installed during software installation when removing packages. You can use apt-get autoremove to perform some housekeeping and remove any dependencies, such as the programs and libraries that the software you once installed but is no longer in use. These dependencies can be removed by running the apt-get autoremove command below, which clears up the system and frees up disk space:

sudo apt-get autoremove

This command will provide a list of all the outdated and unneeded packages as well as any dependencies that are still occupying disk space on your system. Additionally, a Y/N prompt will appear on the screen to confirm the uninstallation process. Clicking Y will start the process of removing the unwanted software dependencies from your system. This is a helpful Ubuntu program uninstalling technique.

Method 5: Using the ppa-purge Command to Uninstall Software Previously Installed Using a PPA

On occasion, users might want to remove software that they installed from PPA repositories from their Ubuntu system. Use the following two ppa-purge commands to remove software that was previously installed through a PPA:

sudo apt-get install ppa-purge

sudo ppa-purge <ppa:repository-name>

The first command gets rid of the PPA-installed software. The PPA is eliminated from sources.list by the second command.

Additional Methods for Uninstalling Software

Ubuntu includes extra software for uninstalling packages outside of the command-line interface because using package managers or the command-line interface isn't always the best option. Let's go over the methods listed below for Linux program uninstallation.

Method 1: Uninstalling Software via the Synaptic Package Manager Uninstall Steps

Ubuntu's GUI package manager, Synaptic, is typically not installed on the server version of the operating system. It is presented here to give a more thorough rundown of uninstall techniques. Follow these steps to uninstall software using Synaptic.

Step 1a: Launch Synaptic Package Manager

All you need to do is open Synaptic Package Manager from your Linux desktop to begin using it. Once it's opened, explore the available packages and easily install or uninstall the ones you need.

Step 1b: Search for the Package to Uninstall

Use Synaptic's top menu search function to locate the package you wish to uninstall. To remove a package, just type its name into Synaptic, and it will list all related packages on your system.

Step 1c: Select Package to Remove

Navigate through the list of installed programs, selecting the program to make it the active window. Once the desired package has been located, right-click on its name to bring up a context menu. Choose Mark for Removal from there.

Note that Synaptic will also mark any dependencies for removal on its own. Generally, this is what you want, but before moving forward, make sure to double-check the list of packages that will be removed.

Step 1d: Apply Changes

Click Apply. By doing this, the program will be removed but the configuration files will remain. Choose Mark for Complete Removal if you would rather have the software and its related configuration files deleted as well.

Step 1e: Wait for Uninstall to Finish

Once you've started the uninstall procedure, Synaptic will show you how the removal is going. The process may take a few seconds to several minutes, depending on the package's size and any dependencies.

Synaptic will show a message stating that the changes were successfully applied after the uninstallation is finished. Congratulations for mastering the art of Ubuntu program uninstallation.

Method 2: Finding & Uninstalling Software Packages via the dpkg --list and dpkg–query -l Uninstall Steps

To obtain a list of all installed packages in Ubuntu, use the dpkg --list command to search for software packages in dpkg. For accuracy's sake, it is a good idea to write down the full name of the software before uninstalling it. One of these commands can be used to list installed software using dpkg. Theless command can be used to search for the command if you know the name of the program, as demonstrated below:

dpkg ––list
dpkg–query –l | less

You can also use the grep command to look for a partial name if you don't know the entire name:

dpkg–query –l | grep package_name
dpkg–query –l | grep *partial_name*

After acquiring the package name, use the dpkg --remove command as demonstrated in the example below:

sudo dpkg --remove <package_name>

Note: Using the dpkg command to install or remove software is not the best option because, in the process of uninstalling the package, it may remove the package in question but leave all of its dependencies on the system, which may cause problems.

Method 3: Uninstalling Software Set Up from the Source Code in Ubuntu

There are a few key things to keep in mind when trying to remove Ubuntu software that was installed from source code:

  • None of the source code that you used to install the program should be removed.
  • Make sure the program has an uninstall option when installing it. It's possible that a badly configured program won't have an uninstall option, in which case you'll need to manually remove every file the software installed.

Note: Using the configure, make, and make install commands, try to restrict the amount of software that is installed on a system. This is because most makefiles lack or do not support an uninstallation process, which limits their functionality. To ensure that uninstalled files and directories are removed and cleaned up, always try to use a package manager that supports tracking of install locations (.deb snap, etc.).

You must locate the software's files and directories before you can uninstall it. The configure, make, and make install commands were probably executed when you compiled and installed the software from source code. All over your system, these commands have installed and created files. You need to find the makefile, which has the make uninstall command, in order to find the files related to the program. The warning is that not every installation of source code comes with a makefile that includes an uninstall command. Authors at the library are responsible for providing that; some do so with an uninstall target, others do not.

Launch the terminal and go to the directory where the source code was extracted to get started. Once there, you have to locate the makefile containing the command to uninstall. The makefile is typically found in the directory where you downloaded the source code. Makefile or makefile, depending on the installed software, is a common name for the file.

After locating the makefile, open it and search for the uninstall command, which ought to be near the end of the file. Run the command in the terminal after copying it. Open a terminal window and type the following command to execute the uninstall command:

sudo make uninstall

This command will look through the software's files and directories and delete them from your computer. Usually, you can use the above-mentioned command in the extracted directory of the program to uninstall it.

Another option is to try running the installation procedure, noting every directory that is mentioned, and then manually deleting the entries to have a look at the steps used to install the software:

sudo make -n install

Normally, you can run the following command to use the makefile to remove the executable file and all of the object files from the directory:

sudo make clean

The make clean command may not entirely uninstall the package, but it usually cleans the directories where the software was installed. It's possible that dependencies applied or required for the installation process won't be removed.

Instead of just using sudo make install, you can also use the checkinstall command, which will probably place files throughout the system that are difficult to remove in the event that something goes wrong. You will encounter errors and the software you compiled may stop working if you try to install a package later on that contains the same file as the software you are compiling.

You can use checkinstall for any installation task outside of apt, and it will keep track of the installation in the package manager. In fact, checkinstall can keep track of files modified by any source install, not just a make install.

This section aims to provide clarification on the process of uninstalling programs in Ubuntu that require the source code.

Method 4: Uninstalling Software Using the Git Uninstall Steps

Git often only copies an external repository to a folder on the local system. You can simply recursively remove the hierarchy of that folder if you used a non-standard prefix when configuring a package to be installed under a particular hierarchy (like under /opt/git/software/).

The application files and settings can be deleted using the git clean command if you installed software using Git:

git clean -xfd

This is a very simple step for Linux program uninstallation if Git was used.

Method 5: Uninstalling Software Using the Snapd Uninstall Steps

Snapd offers a simple way to install and remove software. The following commands can be used from the command line to find the software:

sudo snap list

An overview of all the installed snap packages can be found with the listoption. After that, you can uninstall the software by using the remove option. Use the following command to uninstall a package that was installed using Snapd:

sudo snap remove <package_name>

Method 6: Uninstalling Software Using the Ubuntu Software Manager's Remove Software Functionality

Packages can be installed and uninstalled from your system using a graphical interface that the Ubuntu Software Manager offers. Click the icon in the Activities toolbar to use the Ubuntu Software Manager to uninstall software. This will launch the Ubuntu Software Manager, allowing you to look for, install, and remove programs from your system.

For this purpose, you would locate the software you wish to remove in the list of applications, click the Remove button, and that would be how to uninstall it on Linux. You can delete downloaded archive files using the clean command if you're running low on disk space.

Method 7: Uninstalling Software Using the Flatpak Uninstall Steps

If an application was installed with the help of Flatpak, you can start by looking for it or a list of all the apps that were installed with Flatpak:

sudo flatpak search
sudo flatpak list 

The installed software can then be removed using the flatpak uninstall <package_name> feature, which involves using the flatpak command in conjunction with the application package name. A sample of the command syntax is provided here:

flatpak uninstall <package_name>

Method 8: Uninstalling Software via the AppImage Uninstall Steps

These apps don't require installation; they run directly from the binary file. You can easily delete an AppImage package by doing so.

You do not need to uninstall the AppImage software because it is not installed in the traditional sense of the word. The application can be eliminated by simply deleting the AppImage file; however, the data that the application has generated and/or downloaded will remain. Additionally, you should delete the desktop file from $HOME/.local/share/applications/ in order to remove menu entries.

It might be necessary to unhide files and directories that have dot-based names, such as.example, and that are hidden. The unhide option is typically located in the file manager's settings, or in the settings of many file managers. Usually, you can do this by pressing the keyboard shortcut Ctrl + H.

Method 9: Removing Files & Directories Manually

Use the rm command and the absolute path of the directory you wish to remove in order to manually remove directories. For instance, you would use the following command to remove the directory located at /usr/local/bin/package:

sudo rm -rf /usr/local/bin/package

The directory and all of its contents, including any subdirectories, will be erased by using this command.

FAQs to Remove Packages From Ubuntu via Command Line

Are there any precautions I should take before removing packages on Ubuntu?

Before removing packages, ensure that you are aware of the dependencies and functions of the packages to avoid breaking your system unintentionally.

What distinguishes apt-get remove from apt-get purge when removing packages on Ubuntu?

The difference lies in the fact that apt-get remove eliminates the package while keeping configuration files, whereas apt-get purge not only removes the package but also erases its configuration files.

What happens if I try to remove a package that is not installed on my system?

If you attempt to remove a package that is not installed, Ubuntu will display a message indicating that the package is not found.

Can I remove system-critical packages using the command line?

It is not recommended to remove system-critical packages via the command line as it can disrupt the functioning of your Ubuntu system.

Is it possible to remove multiple packages at once on Ubuntu via the command line?

Yes, it is feasible to remove several packages simultaneously within Ubuntu through the command line interface.

How do I remove a package alongside its dependencies on Ubuntu using the command line?

Removing a package along with its dependencies is achievable by executing specific commands in the Ubuntu terminal.

Is there a method to reverse a package removal action on Ubuntu using the command line?

While Ubuntu doesn't provide a direct undo function, you can reinstall a removed package through the command line if needed.

Conclusion

We hope this tutorial helped you understand how to remove packages from Ubuntu via command line.

If you have any queries, please leave a comment below, and we’ll be happy to respond to them for sure.

Great! You’ve successfully signed up.
Welcome back! You've successfully signed in.
You've successfully subscribed to DevOps Tutorials - VegaStack.
Your link has expired.
Success! Check your email for magic link to sign-in.
Success! Your billing info has been updated.
Your billing was not updated.