简体   繁体   中英

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?

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.

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

运行以下命令:

set JAVA_HOME=C:\Program Files\Java\jre8

I was facing similar issue where Java home is already set but still it was throwing error. Open elasticsearch-plugin.bat file and change "IF DEFINED JAVA_HOME" to "IF DEFINED %JAVA_HOME%" , if you have java home already set.

Thanks

If elasticsearch version is 7.5 or higher, you find elasticsearch-7.XY\\bin directory and then edit the elasticsearch-env.bat as the following:

   if defined JAVA_HOME (
  set JAVA="%WRITE_ELASTICSEARCH_JAVA_PATH%\bin\java.exe" //write java custom path. Edit only this line
  set JAVA_TYPE=JAVA_HOME
) else (
  set JAVA="%ES_HOME%\jdk\bin\java.exe"
  set JAVA_HOME="%ES_HOME%\jdk"
  set JAVA_TYPE=bundled jdk
)

You can customize the java path like that for elasticsearch.

You can set the system-wide environment variables by clicking Start, pointing to 'Computer', right-clicking and selecting properties. Next, click 'Advanced System Settings', hitting the 'Advanced' tab and selecting the 'Environment Variables' button. This brings up a window where you can set your JAVA_HOM E variable. You can do this either for the current user (top box) or system-wide.

环境变量对话框

After doing this, open a new cmd window (Start menu, type ' cmd ' and hit enter) and verify JAVA_HOME is set like in the question above.

This is pretty common error, JAVA_HOME environment is not set. So, we need to set it up in a more prominent basis. What it's asking for the path to the jre directory and not to the bin directory ie java environment path to configure & run the elasticsearch. So, make sure you don't specify the bin directory into your path. Then, you are good to go run your elasticsearch and it will be up and running at default port 9200.

I still couldn't run it even after I set the %JAVA_HOME% environment variable. The problem for me was that I should have ran the elasticsearch.bat file as an administrator . That fixed the issue.

See , you just need to do below: (don't delete any environment variable already set)

  • Step 1: Edit elasticsearch-service.bat located in \\bin
  • Step 2: Add below line at the beginning (below @echo) SET JAVA_HOME=C:\\Program Files\\Java\\jdk1.8.0_162 (or your Java path)
  • Step 3: locate %%JAVA_HOME%% in the same file and replace it with %JAVA_HOME%
  • Step 4: then from cmd in bin folder run: elasticsearch-service.bat install
  • Step 5: That's it, simply run elasticsearch-service now from cmd and it will run.

I get this error because I was using Powershell and it wasn't seeing environment variable . (I don't know way) Then I used CMD and it ran successfully.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM