11

I downloaded Logstash-1.5.0 on Windows 8.1 and tried to run it in the command prompt.

First I checked the java version. Then changed the directory to logstash-1.5.0/bin then entered the command logstash -e 'input { stdin { } } output { elasticsearch { host => localhost } stdout { } }' it gave the following error:

Cannot locate java installation, specified by JAVA_HOME

The Logstash folder is on C: and the version of Java is 1.7.0_25. I've set the JAVA_HOME environmental variables to the jdk /bin directory, but still it doesn't work.

I'm new to Logstash. Can somebody tell me in detail why this happens and help me fix it?

Thorsten S.
  • 4,144
  • 27
  • 41
Asma Zinneera Jabir
  • 801
  • 3
  • 13
  • 31

3 Answers3

16

Set the JAVA_HOME and PATH environmental variables like this:

JAVA_HOME = C:\Program Files\Java\jdk1.7.0_25 
PATH = C:\Program Files\Java\jdk1.7.0_25\bin
Razib
  • 10,965
  • 11
  • 53
  • 80
  • 1
    You can even declare JAVA_HOME the same way within cygwin. No need to use the /cygdrive path. – klimpergeist Feb 15 '17 at 09:59
  • I'm surprised it needs *both* environment variables (both `JAVA_HOME` and `PATH`?). But , logstash does say: `Using JAVA_HOME=C:\ProgramData\Oracle\Java\javapath\java.exe retrieved from PATH` -- so I guess PATH is important! Then why is `JAVA_HOME` also needed? – Nate Anderson Jun 21 '17 at 20:58
  • 1
    @TheRedPea JAVA_HOME may not require in this specific case. But Its good practice setting JAVA_HOME. Cause some java based application (eg. - tomcat, ant) depends on JAVA_HOME. – Razib Jun 22 '17 at 10:28
  • Thanks, I agree with you. Another clarification; should we change the `PATH` **User** variable, or the `Path` **System** variable? ([Related stuff here]). And it turns out that if you *don't* set `JAVA_HOME`, it will still complain: `JAVA_HOME environment variable must be set!`. Thanks again! – Nate Anderson Jun 22 '17 at 12:15
  • For some reason my `AWS` instance would not listen to my environment-variable changes (kept looking in the `C:\ProgramData\Oracle\...`! Even though `PATH` did not mention that), so I just used `set` commands in the command-line session to change them temporarily. Notice also I have newer version, your version may change `set PATH=C:\Program Files\Java\jdk1.8.0_131\bin` and `set JAVA_HOME=C:\Program Files\Java\jdk1.8.0_131` – Nate Anderson Jun 22 '17 at 12:22
2

In my case the problem was that I set the JAVA_HOME variable with a space in the end:

"set JAVA_HOME=c:\Programs\Java " 

instead of

"set JAVA_HOME=c:\Programs\Java"

And logstash couldn't figure that out :) Removing the space fixed the issue.

Nate Anderson
  • 18,334
  • 18
  • 100
  • 135
Tomáš Fejfar
  • 11,129
  • 8
  • 54
  • 82
1

On Windows when you change environment over the system settings, you have to close and reopen the command shell, before the changes take effect.

Step by step:

  1. Locate your java JRE installation directory you want to use. For example: "C:\Program Files\Java\jre7"
  2. Open start menu right click computer and select settings. In System settings window on right side click on "Extended Systemsettings".
  3. On Tab extended select environment variables, add your JAVA_HOME variable to your path and hit OK.
  4. Open command shell and check environment by entering "set" and hit enter. Look if JAVA_HOME is set.

If your JAVA_HOME is now correctly set, logstash should work.

unknown
  • 4,859
  • 10
  • 44
  • 62
Rene M.
  • 2,660
  • 15
  • 24