Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

I need to clean up my server from PHP 5.3 packages (there are plenty of them) in order to be able to compile PHP 5.2. I am wondering what is the easiest/safest method to get rid of them all?


share|improve this question

4 Answers 4

up vote 11 down vote accepted

This should completely remove any package wich name starts with php and anything related to it.

sudo apt-get -y purge php.*
share|improve this answer
Lol. Seems I wans't the only one with this idea :p –  RobinJ Sep 3 '11 at 18:07
OK thanks both of you. I just chosen your answer because Marco does not seem to have lack of Karma :) –  corev Sep 3 '11 at 18:11
Alright, any ideas on the best way to install PHP 5.2 now? –  corev Sep 3 '11 at 18:19
This exact command just wiped ALL the packages from my system. I don't advice anyone to use it ever. –  Caballero Oct 21 '13 at 10:32
php* will get it treated as a regex, and ever package with ph in its name will get removed. –  muru Oct 28 '14 at 19:06

You'll probably want to purge all the php* packages from your system. Something with a wild-card should work

sudo apt-get purge php.*

You may be interested in How to rollback to PHP 5.2 for where to go next.

share|improve this answer
php* will get it treated as a regex, and ever package with ph in its name will get removed. –  muru Oct 28 '14 at 19:05

I do not recommend running sudo apt-get purge php*.

That was scary! Fortunately, I didn't type the -y option, because it chose about hundred of packages without php in their name.

sudo aptitude purge `dpkg -l | grep php| awk '{print $2}' |tr "\n" " "`
share|improve this answer
This should be the accepted answer –  Dark Star1 Aug 4 '14 at 21:28
sudo apt-get -y purge libapache2-mod-php5 libapache2-mod-php5filter libexpect-php5 libgv-php5 libow-php5 php5 php5-adodb php5-auth-pam php5-cgi php5-cli php5-common php5-curl php5-dbg php5-enchant php5-exactimage php5-ffmpeg php5-fpm php5-geoip php5-gmp php5-idn php5-imagick php5-imap php5-interbase php5-intl php5-json php5-lasso php5-ldap php5-librdf php5-mapscript php5-memcache php5-memcached php5-mhash php5-midgard2 php5-ming php5-mssql php5-mysql php5-mysqlnd php5-odbc php5-pgsql php5-ps php5-pspell php5-radius php5-recode php5-remctl php5-rrd php5-sasl php5-snmp php5-sqlite php5-suhosin php5-svn php5-sybase php5-tidy php5-tokyo-tyrant php5-uuid php5-xcache php5-xdebug php5-xmlrpc php5-xsl

In your case, you could search for all the packages:

sudo aptitude search php5|awk {'print $2'}|grep -v i386|grep -v "^A"|tr "\n"  " "

and then purge them:

sudo apt-get purge <list of packages found>
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.