1. Overview

There are several ways we can use to install a package/application in Linux, such as from a repository, manual installation (from a .deb or executable file), Snap, or Flatpak.

In this tutorial, we’ll look at a few ways of completely removing a package that we installed using any of those methods, including its configuration and user profile directories.

2. Removing a Package Installed from a Repository

Let’s say we install the Telegram desktop application from a repository:

$ sudo apt install telegram-desktop
...
The following additional packages will be installed:
fonts-open-sans libxxhash0
The following NEW packages will be installed:
fonts-open-sans libxxhash0 telegram-desktop
...

APT will get and install the telegram-desktop package and two additional packages (fonts-open-sans and libxxhash0) from the repository onto our system.

Once the installation is successful, we can check all the files that the package has copied to our system using dpkg command:

$ dpkg -L telegram-desktop
/.
/usr
/usr/bin
/usr/bin/telegram-desktop
...
/usr/share/man/man1/telegram-desktop.1.gz
/usr/share/metainfo
/usr/share/metainfo/telegramdesktop.appdata.xml

Some applications will also create a directory in ~/.local/share or ~/.config to store their configuration and user profile. For Telegram, it creates ~/.local/share/TelegramDesktop directory.

Now, to remove the Telegram package along with its dependencies and additional packages, we can use apt remove:

$ sudo apt remove --purge --autoremove telegram-desktop

This command has a few parts:

  • remove: remove package
  • purge: remove dependencies
  • autoremove: remove additional packages

We must also remember to use sudo to ensure we have the right access to change what’s installed.

Once the removal process finishes, the telegram-desktop package should no longer exist on our system. Let’s verify this using dpkg:

$ dpkg -L telegram-desktop
dpkg-query: package 'telegram-desktop' is not installed
Use dpkg --contents (= dpkg-deb --contents) to list archive files contents.

The configuration directory (~/.local/share/TelegramDesktop) still exists, but we can remove it manually:

$ rm -r ~/.local/share/TelegramDesktop

Now we’ve completely removed a package installed from a repository.

3. Removing a Package Installed From an Executable File

If we install a package from an executable file and the distributor doesn’t provide a way to uninstall the package, we may need to remove it manually.

Let’s say we downloaded the Telegram application from their website and extracted it to our Downloads directory:

$ ls ~/Downloads/Telegram -l
total 122304
-rwxr-xr-x 1 baeldung baeldung 119899536 Apr 26 17:39 Telegram
-rwxr-xr-x 1 baeldung baeldung 5332648 Apr 26 17:36 Updater

We run the executable file, which will create the desktop shortcut and application configuration files:

$ ./Telegram

Telegram doesn’t provide a way to uninstall the package, so we’ll have to remove it ourselves.

3.1. Removing Application Configuration and User Profile Directories

If the application is installed for the current user only, the application configuration and user profile directories are usually located in ~/.local/share or ~/.config, otherwise it may be located in /opt, /var, or somewhere else.

For Telegram, it’s in ~/.local/share/TelegramDesktop, and we can just remove it:

$ rm -r ~/.local/share/TelegramDesktop

After we have removed the directories, if we run the application again, the application should look like a fresh install. Next, we will remove the application desktop shortcut.

3.2. Removing the Desktop Shortcut

Most applications store the desktop shortcut file (*.desktop) in:

  • /usr/share/applications, or
  • /usr/local/share/applications, or
  • ~/.local/share/applications

We can try looking for it by using the find command to find the .desktop file which has the word ‘Telegram‘ in it in our home directory (~):

$ find ~ -type f -name '*.desktop' 2>/dev/null | grep Telegram
/home/baeldung/.local/share/applications/userapp-Telegram Desktop-5SZOL1.desktop
/home/baeldung/.local/share/applications/appimagekit_ded829c60cac78ccbd38351db01f038f-Telegram_Desktop.desktop

Before we remove the shortcut file, we may want to open it to verify the location of the executable file, which we will remove in the next step:

$ cat ~/.local/share/applications/appimagekit_ded829c60cac78ccbd38351db01f038f-Telegram_Desktop.desktop
[Desktop Entry]
...
TryExec=/home/baeldung/Downloads/Telegram/Telegram
Exec=/home/baeldung/Downloads/Telegram/Telegram -workdir /home/baeldung/.local/share/TelegramDesktop/ -- %u
...

Afterwards, we can remove the shortcut:

$ cat ~/.local/share/applications/appimagekit_ded829c60cac78ccbd38351db01f038f-Telegram_Desktop.desktop
[Desktop Entry]
...
TryExec=/home/baeldung/Downloads/Telegram/Telegram
Exec=/home/baeldung/Downloads/Telegram/Telegram -workdir /home/baeldung/.local/share/TelegramDesktop/ -- %u
...

After we have removed those files, the Telegram icon should no longer appear on the desktop.

3.3. Removing the Package

The final step is to remove the package itself:

$ rm -r ~/Downloads/Telegram

At this point, we should have completely removed the Telegram package from our system.

4. Removing a Package Installed From a .deb File

We can remove a package installed from a .deb file by using the apt command, just as we did earlier:

$ sudo apt remove --purge --autoremove telegram-desktop

Then we need to find the configuration directory and remove it manually. For example, for Telegram application, it’s in ~/.local/share/TelegramDesktop:

$ rm -r ~/.local/share/TelegramDesktop

At this point, we should have completely removed the package that we installed from the .deb file.

5. Removing a Package Installed by Snap

Snap is another package management system that bundles the package with all its dependencies.

When we install an application using Snap, it stores all files in the ~/snap directory.

To remove a Snap package we use snap remove:

$ snap remove telegram-desktop

If the removal process is successful, the directory ~/snap/telegram-desktop should disappear.

6. Removing a Package Installed with Flatpak

Flatpak is also another package management system.

When we install an application using Flatpak, it stores all files in /var/lib/flatpak/app directory.

To remove a Flatpak package we use flatpak uninstall:

$ flatpak uninstall org.telegram.desktop

If the removal process is successful, the directory /var/lib/flatpak/app/org.telegram.desktop should disappear.

7. Conclusion

In this article we ran through several methods to install and uninstall a package in Linux Debian, such as using APT, Snap, or Flatpak.

We also traced and removed the package config and user profile files manually.