How to uninstall Elasticsearch on a linux server isn’t well documented. Here’s a clear set of instruction on how to do it.
First confirm that Elasticsearch is not actively running.
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
.
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 use the service
command. First check if a service
exists using the following command:
sudo service elasticsearch status
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
Depending on how elasticsearch was installed, and what type of server you’re running, you’ll need to use one of the following approaches to uninstall it.
The apt-get
command is usually found on Ubuntu, Debian, and related Linux distributions.
sudo apt-get remove elasticsearch
The rpm
command is typically found on Red Hat linux machines like CentOS and Fedora.
rpm -e elasticsearch
The yum
command exists on Red Hat linux machines using Red Hat Enterprise Linux RPM software packages.
sudo yum remove elasticsearch
The final step to uninstall elasticsearch from a server is to clear out the leftover configuration files.
sudo apt-get --purge autoremove elasticsearch
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
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.
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 guarantee or warranty on any of this advice, use it at your own risk.