Uninstalling Elasticsearch on your own linux server isn’t that straight forward or well documented. This guide walks through the process of uninstalling step by step for reference to anyone that needs a simple guide.
Check for Running Instances
The first step on all systems is to confirm that Elasticsearch is not actively running.
Option #1: curl
Check for a running server on the machine’s localhost
with curl
:
curl localhost:9200
If one is you’ll see a response containing elasticsearch
.
Option #2: ps
Check for a running server process using ps
:
ps -ef | grep elas
If one exists you’ll see it returned, if you don’t see anything then no elasticsearch
process is running.
To stop a running process
Option #3: service
Check if a service
exists using the following command:
sudo service elasticsearch status
Shutdown Elasticsearch
If you found any actively running elasticsearch processes in the previous step then you can shut it down using one of the following approaches:
curl
curl -XPOST https://localhost:9200/_cluster/nodes/_shutdown
ps
killall -KILL elas
service
sudo service elasticsearch stop
Uninstalling Elasticsearch
Depending on how you installed it, and what type of server you’re running you’ll need to use one of the following approaches.
Apt
The apt-get
command is usually found on Ubuntu, Debian, and related Linux distributions.
sudo apt-get remove elasticsearch
RPM
The rpm
command is typically found on Red Hat linux machines like CentOS and Fedora.
rpm -e elasticsearch
YUM
The yum
command exists on Red Hat linux machines using Red Hat Enterprise Linux RPM software packages.
sudo yum remove elasticsearch
Purging Elasticsearch Config
The final step to uninstall elasticsearch from a server is to clear out the leftover configuration files.
APT
sudo apt-get --purge autoremove elasticsearch
dpkg
sudo dpkg --purge elasticsearch
If you receive any errors and need to force the removal you can add a --force-all
argument to the command:
sudo dpkg --purge --force-all elasticsearch
Final Step
The final step for a super clean uninstall is to manually remove the following directories that are leftover on the system:
sudo rm -rf /var/lib/elasticsearch/
sudo rm -rf /etc/elasticsearch
You can also remove the service script, but the location will vary from server to server.
Disclaimer
These steps may change over time, or may not work on your system. It’s important that you know what you’re doing and take full responsibility for the outcome of this process. I may no gurantee or warranty on any of this advice, use it at your own risk.