Elasticsearch 7.9.1 won't start on a Windows host after creating a JAVA_HOME environment variable

  • KM03808366
  • 06-May-2021
  • 06-May-2021


Creating a JAVA_HOME environment variable which points to a specific Java installation outside of the Elasticsearch directory causes the service to fail


In the Windows Event viewer logs, System, the following error will exist for the Elasticsearch service...

The Elasticsearch 7.9.1 (elasticsearch-service-x64) service terminated unexpectedly.  It has done this x time(s).


This is caused by an Oracle or OpenJDK JRE/JDK defined as JAVA_HOME on the Elasticsearch host
Elasticsearch 7.9.x includes its own OpenJDK which it expects


Two approaches...

Option A
Set the JAVA_HOME environment variable on the Elasticsearch host to point to the OpenJDK within the Elasticsearch directory, for example...

Option B
1) Open the "elasticsearch-service.bat" for editing
2) The first line in the file will be the line: @echo off
3) Directly underneath the line "@echo off", specify the path to the OpenJDK included with Elasticsearch, for example...
SET JAVA_HOME=D:\Elastic\elasticsearch-7.9.1\jdk
Note: mind the path for the "jdk" folder for the Elasticsearch instance in question as this is likely different that the example above
4) Save Changes
5) Open a cmd prompt and navigate to the "elasticsearch-service.bat" in the "bin" directory (...elasticsearch-7.9.1\bin)
6) Remove the service by typing: elasticsearch-service.bat remove
7) Re-establish the service by typing: elasticsearch-service.bat install

The Elasticsearch service should now start normally