When software is installed in Ubuntu using apt or the Ubuntu Software Center, the system retrieves .deb packages and places them in system directories, including executables and configuration files. In many cases, these installations also create data directories linked to the application, which can reside in both system and user paths.
Removing a program through apt remove or apt-get remove often leaves behind configuration files and shared dependencies. These remnants can clutter the operating system and potentially cause conflicts or errors during future software installations or upgrades.
Maintaining a clean environment requires removing all binaries, associated configuration, and leftover data. This approach optimizes disk usage and ensures minimal interference with future packages or updates.
Steps to completely remove program in Ubuntu and Debian:
- Open the terminal.
- 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]
- 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
- Confirm deletion if prompted.
- 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
- 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 |

Mohd Shakir Zakaria is a cloud architect with deep roots in software development and open-source advocacy. Certified in AWS, Red Hat, VMware, ITIL, and Linux, he specializes in designing and managing robust cloud and on-premises infrastructures.
Comment anonymously. Login not required.