As a Java application, setting up Elasticsearch has always required having Java set up and the JAVA_HOME
environment variable pointing to it. See, for instance, my articles on setting up Elasticsearch on Windows and setting up Elasticsearch on Linux.
From version 7, Elasticsearch is making things a lot easier by bundling a version of OpenJDK with Elasticsearch itself.
“One of the more prominent “getting started hurdles” we’ve seen users run into has been not knowing that Elasticsearch is a Java application and that they need to install one of the supported JDKs first. With 7.0, we’re now releasing versions of Elasticsearch which pre-bundle the JDK to help users get started with Elasticsearch even faster. If you want to bring your own JDK, you can still do so by setting JAVA_HOME before starting Elasticsearch. “
— Elasticsearch 7.0.0 released | Elastic Blog
The documentation tells us more about the bundled JDK:
” Elasticsearch is built using Java, and includes a bundled version of OpenJDK from the JDK maintainers (GPLv2+CE) within each distribution. The bundled JVM is the recommended JVM and is located within the
— Set up Elasticsearch | Elasticsearch Reference [7.2] | Elasticjdk
directory of the Elasticsearch home directory.
“To use your own version of Java, set theJAVA_HOME
environment variable. If you must use a version of Java that is different from the bundled JVM, we recommend using a supported LTS version of Java. Elasticsearch will refuse to start if a known-bad version of Java is used. The bundled JVM directory may be removed when using your own JVM.”
Therefore, after downloading a fresh version of Elasticsearch (7.2 is the latest at the time of writing this), we notice that there is a jdk
folder as described above:
On a machine with no JAVA_HOME
set, Elasticsearch will, as from version 7, use this jdk
folder automatically:
This means that we can now skip the entire section of setting up Elasticsearch that revolves around having a version of Java already available and setting the JAVA_HOME
environment variable.
On the other hand, if you do have JAVA_HOME
set, Elasticsearch will use that, and will not use the bundled JDK at all. This in turn means that if you have JAVA_HOME
set incorrectly (e.g. to a directory that no longer exists), Elasticsearch fails with a misleading error that seems to indicate that it’s also looking for the bundled JDK:
"could not find java in JAVA_HOME or bundled at C:\tools\elasticsearch-7.2.0\jdk"
Therefore, if you want to use our own JDK, then make sure JAVA_HOME
is set correctly. If you want to use the bundled one, then make sure JAVA_HOME
is not set.