When you install programs in Ubuntu using apt or the Ubuntu Software Center, the system downloads and installs .deb packages along with their dependencies. These packages are placed in system directories, including executables and configuration files. The installation process may also create additional data files or directories related to the application.

Uninstalling a program using apt or apt-get remove does not delete all associated files. Configuration files and dependencies often remain, causing unnecessary clutter on the system. These leftovers can lead to potential conflicts if you reinstall the application or its dependencies later.

To ensure a clean system, you must remove all residual files after uninstalling a program. This includes deleting program binaries, configuration files, and any related data files. A thorough cleanup will optimize disk space and maintain system efficiency.

Steps to completely remove program in Ubuntu and Debian:

  1. Open the terminal.
  2. Identify the package name of the program you want to remove.
    $ sudo apt list --installed | grep mariadb
    
    WARNING: apt does not have a stable CLI interface. Use with caution in scripts.
    
    mariadb-client-10.3/focal,now 1:10.3.22-1ubuntu1 amd64 [installed,automatic]
    mariadb-client-core-10.3/focal,now 1:10.3.22-1ubuntu1 amd64 [installed,automatic]
    mariadb-common/focal,now 1:10.3.22-1ubuntu1 all [installed,automatic]
    mariadb-server-10.3/focal,now 1:10.3.22-1ubuntu1 amd64 [installed,automatic]
    mariadb-server-core-10.3/focal,now 1:10.3.22-1ubuntu1 amd64 [installed,automatic]
    mariadb-server/focal,now 1:10.3.22-1ubuntu1 all [installed]
  3. Purge the package to remove associated configuration files.
    $ sudo apt purge mariadb-server
    Reading package lists... Done
    Building dependency tree
    Reading state information... Done
    The following packages were automatically installed and are no longer required:
      galera-3 libcgi-fast-perl libcgi-pm-perl libconfig-inifiles-perl
      libdbd-mysql-perl libdbi-perl libencode-locale-perl libfcgi-perl
      libhtml-parser-perl libhtml-tagset-perl libhtml-template-perl
      libhttp-date-perl libhttp-message-perl libio-html-perl
      liblwp-mediatypes-perl libmysqlclient21 libsnappy1v5 libterm-readkey-perl
      libtimedate-perl liburi-perl mariadb-client-10.3 mariadb-client-core-10.3
      mariadb-common mariadb-server-10.3 mariadb-server-core-10.3 mysql-common
      socat
    Use 'sudo apt autoremove' to remove them.
    The following packages will be REMOVED:
      mariadb-server*
    0 upgraded, 0 newly installed, 1 to remove and 0 not upgraded.
    After this operation, 68.6 kB disk space will be freed.
    Do you want to continue? [Y/n]
    ##### snipped
  4. Confirm deletion if prompted.
  5. Remove any unused dependencies with the apt autoremove command.
    $ sudo apt autoremove --purge
    Reading package lists... Done
    Building dependency tree
    Reading state information... Done
    The following packages will be REMOVED:
      galera-3* libcgi-fast-perl* libcgi-pm-perl* libconfig-inifiles-perl*
      libdbd-mysql-perl* libdbi-perl* libencode-locale-perl* libfcgi-perl*
      libhtml-parser-perl* libhtml-tagset-perl* libhtml-template-perl*
      libhttp-date-perl* libhttp-message-perl* libio-html-perl*
      liblwp-mediatypes-perl* libmysqlclient21* libsnappy1v5*
      libterm-readkey-perl* libtimedate-perl* liburi-perl* mariadb-client-10.3*
      mariadb-client-core-10.3* mariadb-common* mariadb-server-10.3*
      mariadb-server-core-10.3* mysql-common* socat*
    0 upgraded, 0 newly installed, 27 to remove and 0 not upgraded.
    After this operation, 173 MB disk space will be freed.
    Do you want to continue? [Y/n]
    ##### snipped 
  6. Manually delete any remaining configuration or data files in the system and user directories.
    $ sudo ls -l /etc/mysql /var/lib/mysql
    ls: cannot access '/etc/mysql': No such file or directory
    ls: cannot access '/var/lib/mysql': No such file or directory

    Some program does not properly clean up so the configuration and data files might still exist.

This guide is tested on Ubuntu:

Version Code Name
22.04 LTS Jammy Jellyfish
23.10 Mantic Minotaur
24.04 LTS Noble Numbat
Discuss the article:

Comment anonymously. Login not required.