Remove LAMP in Ubuntu

October 18, 2010 by
Filed under: HowTo, linux, Ubuntu, web development 

The most popular post on this site is the one showing how to install a LAMP server on Ubuntu. Once you're done developing your websites on your computer, you may want to remove the LAMP server from your Ubuntu installation. Actually, you probably want to leave the Linux part and only remove the AMP part, (Apache, MySQL, php).

I've done a post previously that shows how to do this in several steps, but I wanted to come up with a more automated way. So I came up with this one-liner that will remove Apache, MySQL, php, and phpMyAdmin from your Ubuntu system.

Warning: this command will uninstall the packages from your system without asking for confirmation.

dpkg -l *apache* *mysql* phpmyadmin | grep ^ii | awk '{ print $2}' | xargs sudo apt-get -y purge --auto-remove

If you're a bit unsure about doing this and you only want to see a list of packages that will be removed, just leave off the end portion from the last pipe onward, like this.

Affiliate Link
dpkg -l *apache* *mysql* phpmyadmin | grep ^ii | awk '{ print $2}'


14 Responses to “Remove LAMP in Ubuntu”

  1. TeenDev says:

    Nice, not only did it remove LAMP, but it also got rid of KDE when the usual command to remove it wasn't working. Sometimes side-effects are useful :-)

  2. thanks, worked perfectly for me. Now i can re-install lamp from the scratch.

  3. L-Regbot says:

    Vorsicht! This tears out your Kubuntu/KDE-Desktop too! (At least on my Kubuntu 12.10)

    • Linerd says:

      You're right! I just tried it on Kubuntu 12.04 and it happened to me. It's easily fixed with:

      sudo apt-get install kubuntu-desktop

      Apparently kubuntu-desktop has some MySQL dependencies. After reinstalling it everything seems to be fine. All of my other software is still there.

  4. mahfud says:

    -may i delete every folder like's apache2, php5, mysql, and phpmyadmin?
    i was panic and i do that.. and my lamp was error.. they did'nt work well.. :(
    can you give some guide,, how to reinstall my lamp ?


  5. Gabriel says:

    Little heads up, this command removed my Eclipse packages and my Eclipse-platform

  6. dhamaso says:

    this don't will delete the var/www/ directory right?

  7. Josh says:

    Thanks so much! That made life easy. Lamp is gone!

  8. Ven says:

    thank you..
    i want to reinstall my lamp

  9. Willow Wright says:

    I am running Ubuntu 10.04 under Virtual Box on a MAC Host. I have attempted to do a LAMP installation per instructions found online. I have successfully installed everything but the PHPMyAdmin. Something is wrong with the installation, but I have no way of knowing what it is. The command line instructions for the install, were clear, the process just wouldn't complete. And I've tried to go back and re-install PHPMyAdmin several times, now it tells me there's nothing to change or update, but I cannot access PHPMyAdmin in a browser, so it was obviously unsuccessful.

    I want to uninstall JUST the PHPMyAdmin and try again. Can you give me a line of code that would do that?

    Thanks, WCW

  10. Timothy says:

    This would be better in a for loop (eliminating the need for xargs):
    for pkg in `dpkg -l *apache* *mysql* phpmyadmin | grep ^ii | awk '{ print $2}'`; do apt-get -y purge --auto-remove $pkg; done;

    • Linerd says:

      I gave your command a try. It works as long as I add a sudo to the apt-get command so it looks like this:

      for pkg in `dpkg -l *apache* *mysql* phpmyadmin | grep ^ii | awk '{ print $2 }'`; do sudo apt-get -y purge --auto-remove $pkg; done;

      What I don't like about it is that it ends up running apt-get multiple times. apt-get carries some overhead with it, so your command will take longer to execute. I did a little benchmarking to confirm my suspicion. My command takes about 45 seconds to execute on my computer while your version takes about 74 seconds. In the end, it's not a big deal either way.

      It just goes to show that there are often many ways to do things. I don't tend to use for loops very often on the command line, so thanks for offering your perspective.

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>