Skip to content

Instantly share code, notes, and snippets.

@eliyas5044
Created January 16, 2025 06:12
Show Gist options
  • Save eliyas5044/66adcc1ae3cf0c49ebdd4dd6f33f6ce3 to your computer and use it in GitHub Desktop.
Save eliyas5044/66adcc1ae3cf0c49ebdd4dd6f33f6ce3 to your computer and use it in GitHub Desktop.
Uninstall Nginx, Let's encrypt from a Ubuntu server

To completely remove NGINX and Let's Encrypt (Certbot) from your Ubuntu server, you'll need to perform a series of steps to ensure that all files, configurations, and dependencies are properly removed.

Here's how to do it:

1. Stop and disable NGINX

Before you remove NGINX, make sure it's stopped and disabled:

sudo systemctl stop nginx
sudo systemctl disable nginx

2. Remove NGINX packages

You can uninstall NGINX and its associated packages using apt:

sudo apt-get purge nginx nginx-common nginx-full nginx-core nginx-doc

This will remove NGINX and its common configuration files. To make sure you also remove any unused dependencies:

sudo apt-get autoremove

Additionally, you can clean up residual configuration files:

sudo apt-get autoclean

3. Delete NGINX configuration and log files

Even after removing the NGINX packages, some configuration files may still remain in /etc/nginx and log files in /var/log/nginx. Delete these manually:

sudo rm -rf /etc/nginx
sudo rm -rf /var/log/nginx

4. Remove Let's Encrypt (Certbot)

If you've used Certbot (Let's Encrypt) to manage SSL certificates, you'll need to uninstall it as well.

Remove Certbot and its dependencies

First, remove Certbot:

sudo apt-get purge certbot python3-certbot-nginx

Then remove any remaining unused dependencies:

sudo apt-get autoremove

Remove Let's Encrypt certificates and configuration

Let's Encrypt stores its certificates and related files under /etc/letsencrypt. To delete the certificates and all associated data:

sudo rm -rf /etc/letsencrypt

Additionally, you can delete logs from Let's Encrypt:

sudo rm -rf /var/log/letsencrypt

Remove cron jobs (if applicable)

If you set up Certbot for automatic certificate renewal using cron jobs, check if they still exist and remove them.

  • To remove any Certbot-related cron jobs:
sudo crontab -e

Look for lines related to Certbot and remove them.

Alternatively, if you set up a systemd timer for automatic renewal, you can disable and remove it:

sudo systemctl stop certbot.timer
sudo systemctl disable certbot.timer

5. Clean up any remaining dependencies

You can run the following commands to remove any remaining orphaned packages or dependencies:

sudo apt-get autoremove --purge
sudo apt-get clean

6. Check if anything is left behind

You can run dpkg to check if there are any remaining NGINX or Certbot-related packages:

dpkg -l | grep -i nginx
dpkg -l | grep -i certbot
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment