
Debian and Debian-based Linux distributions (such as Ubuntu, Linux Mint and more) use APT as package manager to install and maintain packages.
Remove a single package
To remove a single package, the following command is most likely known to most Debian (command line) users:
root@debian:~# apt-get remove <pkgname>
Note: Check out this helpful APT command overview and comparison to other package commands.
Remove multiple packages
Multiple packages can be added in the same command, with a space as package separator:
root@debian:~# apt-get remove <pkg1> <pkg2> <pkg3> <pkg4>
Remove multiple packages using a wildcard
But sometimes you might have to add a lot of packages to be removed. Here's a typical example showing an outdated PHP version which should be removed. Each PHP module has its own package, therefore there can be a lot of packages installed:
root@debian:~# dpkg -l|grep php
ii php-common 2:95+0~20240927.54+debian11~1.gbpe0084c all Common files for PHP packages
ii php7.4-apcu 5.1.24-1+0~20241124.41+debian11~1.gbpff678c amd64 APC User Cache for PHP
ii php7.4-apcu-bc 1.0.5-19+0~20230618.29+debian11~1.gbp6ddc4e amd64 APCu Backwards Compatibility Module
ii php7.4-apcu-bc-dbgsym 1.0.5-19+0~20230618.29+debian11~1.gbp6ddc4e amd64 debug symbols for php7.4-apcu-bc
ii php7.4-apcu-dbgsym 5.1.24-1+0~20241124.41+debian11~1.gbpff678c amd64 debug symbols for php7.4-apcu
ii php7.4-bcmath 1:7.4.33-18+0~20241224.97+debian11~1.gbpaac02c amd64 Bcmath module for PHP
ii php7.4-bz2 1:7.4.33-18+0~20241224.97+debian11~1.gbpaac02c amd64 bzip2 module for PHP
ii php7.4-cli 1:7.4.33-18+0~20241224.97+debian11~1.gbpaac02c amd64 command-line interpreter for the PHP scripting language
ii php7.4-common 1:7.4.33-18+0~20241224.97+debian11~1.gbpaac02c amd64 documentation, examples and common module for PHP
ii php7.4-curl 1:7.4.33-18+0~20241224.97+debian11~1.gbpaac02c amd64 CURL module for PHP
ii php7.4-fpm 1:7.4.33-18+0~20241224.97+debian11~1.gbpaac02c amd64 server-side, HTML-embedded scripting language (FPM-CGI binary)
ii php7.4-gd 1:7.4.33-18+0~20241224.97+debian11~1.gbpaac02c amd64 GD module for PHP
ii php7.4-gmp 1:7.4.33-18+0~20241224.97+debian11~1.gbpaac02c amd64 GMP module for PHP
ii php7.4-intl 1:7.4.33-18+0~20241224.97+debian11~1.gbpaac02c amd64 Internationalisation module for PHP
ii php7.4-json 1:7.4.33-18+0~20241224.97+debian11~1.gbpaac02c amd64 JSON module for PHP
ii php7.4-mbstring 1:7.4.33-18+0~20241224.97+debian11~1.gbpaac02c amd64 MBSTRING module for PHP
ii php7.4-mcrypt 3:1.0.7-5+0~20241125.20+debian11~1.gbp16148e amd64 PHP bindings for the libmcrypt library
ii php7.4-mysql 1:7.4.33-18+0~20241224.97+debian11~1.gbpaac02c amd64 MySQL module for PHP
ii php7.4-opcache 1:7.4.33-18+0~20241224.97+debian11~1.gbpaac02c amd64 Zend OpCache module for PHP
ii php7.4-readline 1:7.4.33-18+0~20241224.97+debian11~1.gbpaac02c amd64 readline module for PHP
ii php7.4-xml 1:7.4.33-18+0~20241224.97+debian11~1.gbpaac02c amd64 DOM, SimpleXML, XML, and XSL module for PHP
ii php7.4-xmlrpc 1:7.4.33-18+0~20241224.97+debian11~1.gbpaac02c amd64 XMLRPC-EPI module for PHP
ii php7.4-zip 1:7.4.33-18+0~20241224.97+debian11~1.gbpaac02c amd64 Zip module for PHP
ii php8.1-apcu 5.1.24-1+0~20241124.41+debian11~1.gbpff678c amd64 APC User Cache for PHP
ii php8.1-apcu-dbgsym 5.1.24-1+0~20241124.41+debian11~1.gbpff678c amd64 debug symbols for php8.1-apcu
ii php8.1-bcmath 8.1.31-1+0~20241121.67+debian11~1.gbp9e3dc4 amd64 Bcmath module for PHP
ii php8.1-cli 8.1.31-1+0~20241121.67+debian11~1.gbp9e3dc4 amd64 command-line interpreter for the PHP scripting language
ii php8.1-common 8.1.31-1+0~20241121.67+debian11~1.gbp9e3dc4 amd64 documentation, examples and common module for PHP
ii php8.1-curl 8.1.31-1+0~20241121.67+debian11~1.gbp9e3dc4 amd64 CURL module for PHP
ii php8.1-fpm 8.1.31-1+0~20241121.67+debian11~1.gbp9e3dc4 amd64 server-side, HTML-embedded scripting language (FPM-CGI binary)
ii php8.1-gd 8.1.31-1+0~20241121.67+debian11~1.gbp9e3dc4 amd64 GD module for PHP
[...]
But as all PHP packages start with the same name convention (phpX.Y-module), we can tell APT to remove all the packages matching a wildcard. The wildcard character is an asterisk (*).
To remove all PHP 7.4 packages, we can therefore run this command:
root@debian:~# apt-get remove php7.4-*
APT then makes a lookup on all available (not only installed) packages matching php7.4-*. The output also shows when a non-installed package was selected for removal:
Note, selecting 'php7.4-ast' for glob 'php7.4-*'
Package 'php7.4-ast' is not installed, so not removed
At the end of the output, the relevant (installed) packages which will be removed are listed:
The following packages will be REMOVED:
php7.4-apcu php7.4-apcu-bc php7.4-apcu-bc-dbgsym php7.4-apcu-dbgsym php7.4-bcmath php7.4-bz2 php7.4-cli php7.4-common php7.4-curl php7.4-fpm php7.4-gd php7.4-gmp php7.4-intl php7.4-json php7.4-mbstring php7.4-mcrypt php7.4-mysql
php7.4-opcache php7.4-readline php7.4-xml php7.4-xmlrpc php7.4-zip
0 upgraded, 0 newly installed, 22 to remove and 0 not upgraded.
After this operation, 21.3 MB disk space will be freed.
Do you want to continue? [Y/n] y