Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ElasticSearch and Java environment variable

For Windows 7, I've installed JDK in both 32 and 64 bit versions. The versions are 8, update 20 for all four installations. http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html

when I download and unzip elasticsearch, and run /bin/service.bat or /bin/elasticsearch.bat files, I get in my terminal:

JAVA_HOME environment variable must be set! Press any key to continue . . .

When I do, the terminal closes.

I've uninstalled and reinstalled, but that didn't fix it. Why wouldn't the environment varaible get set? Is it an installation thing, or do I actually have to manually set the variable. It just seems like if it installed correctly, it would set the variable automatically... Please help. Thanks

I've manually set the JAVA_HOME environment variable using this.

https://confluence.atlassian.com/display/DOC/Setting+the+JAVA_HOME+Variable+in+Windows

My path is C:\Progra~1\Java\jdk1.8.0_20\jre

Now, when I run service.bat, the terminal immediately closes upon opening. When I run elasticsearch.bat, the terminal prints some lines, and after a while, it just stays there, and I can't type anything.


EDIT:

I uninstalled all java, reinstalled only the JRE 64 bit, and set the system environment variable to JAVA_HOME and `C:\Progra~1\Java\jre1.8.0_20

I have discovered that there is CLASSPATH that's set to a 32bit, older java version. Should I delete that variable?

like image 273
ahnbizcad Avatar asked Aug 30 '14 07:08

ahnbizcad


People also ask

How do I set Java path in Elasticsearch?

According to the Elasticsearch configuration docs, you can edit /etc/default/elasticsearch and set JAVA_HOME there for Elasticsearch.

How do I set environment variables in Elasticsearch?

You need to provide a user name and password for access to Elasticsearch and, optionally, a path to store Elasticsearch data. You can also set how long generated certificates are valid. You must set the variables that have no default value before you run the bai-start command.

Does Elasticsearch use Java?

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 jdk directory of the Elasticsearch home directory.


2 Answers

STEP 1

Can you verify JAVA_HOME is set to C:\Progra~1\Java\jdk1.8.0_20,

C:\>echo %JAVA_HOME% 

Also, verify java command is available,

 java -version 

Reference

Check if JAVA_HOME is present in environment using batch script

STEP 2

If JAVA_HOME is not set, please follow the steps provided here - How to Set Java Home in windows

Summary ,

  • Right-click the My Computer icon on your desktop and select Properties.
  • Click the Advanced tab. Click the Environment Variables button. Under System Variables, click New.
  • Enter the variable name as JAVA_HOME.
  • Enter the variable value as the installation path for the JDK.

    (eg. C:\Progra~1\Java\jdk1.8.0_20).

  • Click OK.
  • Click Apply Changes.
like image 183
prayagupa Avatar answered Oct 16 '22 13:10

prayagupa


A workaround if you do not have privileges to set up the environmental variables:

open the elasticsearch.bat file,

a) Remove the line:

if NOT DEFINED JAVA_HOME goto err 

b) Replace %JAVA_HOME% with your java jdk path, something like: C:\Program Files\Java\jdk1.7.0_51

And for your terminal getting started and you not being able to type anything, it is the elasticsearch server, you need to connect to it using a client like cygwin.

https://cygwin.com/install.html

For connecting to the server refer the elasticsearch documentation.

http://www.elasticsearch.org/guide/

A similar question has already been answered:

"JAVA_HOME points to an invalid Java installation issue" with service install command in elastic search

like image 42
BatScream Avatar answered Oct 16 '22 11:10

BatScream