Hadoop on Windows - "Error JAVA_HOME is incorrectly set."
Asked Answered
B

10

24

I'm trying to get Hadoop running 'Local Mode' on my Windows machine. I've been using this guide: http://hadoop.apache.org/docs/r1.2.1/single_node_setup.html

When I run the command: bin/hadoop, I get the following error message:

Error: JAVA_HOME is incorrectly set. Please update C:...\hadoop-2.7.1\conf\hadoop-env.cmd

Inside hadoop-env.cmd, I have the line: set JAVA_HOME=%JAVA_HOME%

When I type echo %JAVA_HOME% at the command line I get: C:\Java\jdk1.0.8_51

Even if I change the line in hadoop-env.cmd to: set JAVA_HOME=C:\Java\jdk1.0.8_51 I get the same error...

How could it be that my JAVA_HOME is incorrectly set?

Backstroke answered 24/7, 2015 at 23:0 Comment(5)
Try setting JAVA_HOME environment variable at a system level not just your shell (assuming you just set it in the shell). If not then run 'Java -version' at a command prompt.Eris
Thanks for your response Heath. I have set it at a system level. I have a system variable JAVA_HOME=C:\Java\jdk1.0.8_51 ; and I have C:\Java\jdk1.0.8_51\bin in my PATH user variable. Typing in Java -version at the prompt returns -> "java version 1.8.0_51..."Backstroke
Does opening a new prompt and running hadoop work nowEris
No. Sorry, I should have included a mention of that in my previous comment.Backstroke
check this to resolve your issue https://mcmap.net/q/512853/-hadoop-installation-on-windowsFencing
A
33

If your JAVA_HOME path contains spaces, you must use the Windows 8.3 Pathname

Augustin answered 5/12, 2015 at 19:55 Comment(3)
is right! Thanks for saving my day. Just want to make it more detial, if you use the default setting while installing JAVA, you will have to set the JAVA_HOME to something like "C:\Progra~1\Java\jdk1.8.0_xxx". (Don't forget to replace xxx to your actual jdk update id.)Forsta
Right! I also encountered the JAVA_HOME problem. But then, I got another error message "Error: Could not find or load main Trung"Pappus
@Duong edit set HADOOP_IDENT_STRING=%USERNAME% to HADOOP_IDENT_STRING=username(without space) in hadoop-env.cmd filePlovdiv
C
37

like the other answers, your java environment path must not contain space. The solution is as follows:

  1. In the cmd line, charge the directory that contain the jdk (in my case C:\Program Files\Java\jdk1.8.0_73).

  2. execute the following line:
    for %I in (.) do echo %~sI
    to display the short name of your installed jdk (in my case C:\PROGRA~1\Java\JDK18~1.0_7)

  3. in the file "hadoop-env.cmd", change the line "JAVA_HOME=%JAVA_HOME%" with "JAVA_HOME=C:\PROGRA~1\Java\JDK18~1.0_7".

  4. run again the file "hadoop-env.cmd" and it will work correctly.

Cordelia answered 25/7, 2018 at 16:40 Comment(1)
That was awesome. Saved my day! Thank you a lot!Predigestion
A
33

If your JAVA_HOME path contains spaces, you must use the Windows 8.3 Pathname

Augustin answered 5/12, 2015 at 19:55 Comment(3)
is right! Thanks for saving my day. Just want to make it more detial, if you use the default setting while installing JAVA, you will have to set the JAVA_HOME to something like "C:\Progra~1\Java\jdk1.8.0_xxx". (Don't forget to replace xxx to your actual jdk update id.)Forsta
Right! I also encountered the JAVA_HOME problem. But then, I got another error message "Error: Could not find or load main Trung"Pappus
@Duong edit set HADOOP_IDENT_STRING=%USERNAME% to HADOOP_IDENT_STRING=username(without space) in hadoop-env.cmd filePlovdiv
S
23
 set JAVA_HOME=C:\Program Files\Java\jdk1.8.0_131\

Above configuration was throwing same error as yours. I updated above with below in hadoop-env.cmd which is infact SFN

set JAVA_HOME=C:\Progra~1\Java\jdk1.8.0_131\

This allowed me to change/have different java version than that of system.

Shortlived answered 15/8, 2018 at 13:18 Comment(0)
S
3

Try to place the java path in double-coats. Example:

JAVA_HOME="C:\Program Files\Java\jdk-12.0.1"   

It should work fine.

Skeens answered 10/11, 2021 at 7:27 Comment(1)
That's not working. spark-shell for example will throw error.Katushka
O
2

Use "%JAVA_HOME%" in conf\hadoop-env.cmd

Obed answered 31/12, 2015 at 6:38 Comment(0)
A
1

if your java environment path contains space, such as "C:\Program Files\java\xxxxx" , the word 《Program Files》 contains a space, so CMD can't identificate

this is the right answer

Adeno answered 7/8, 2017 at 16:13 Comment(0)
A
1

Try removing @ from @rem in hadoop-env.cmd and set JAVA_HOME=%JAVA_HOME%

rem The java implementation to use.  Required.

set JAVA_HOME=%JAVA_HOME%

Then try running hdfs namenode -format

This solution worked for me

Anthe answered 26/11, 2018 at 5:52 Comment(0)
P
1

error vs fixed

Explanation : C:\Program Files\Java\jdk-11 If you set this path to "System Environment Variables", Java will work normally on your machine. (jdk11 can be different in your case)

But when it comes to Hadoop, it looks like this in "hadoop-env.cmd" file :

set JAVA_HOME=C:\Program Files\Java\jdk-11 : "hadoop-env.cmd" file will ignore path after space : C:\Program + Files\Java\jdk-11 will be treated as two different things.

Solution :

step 1 : Copy "Java" folder from C:\Program Files\Java and paste it in "C:" directory, it will look like this : "C:\Java"

step 2 : Now edit "hadoop-env.cmd" file : set JAVA_HOME=C:\Java\jdk-11

step 3 : make sure to give same path in "System Environment Variables" :

"JAVA_HOME" : C:\Java\jdk-11 & "path" : C:\Java\jdk-11\bin

Restart your IDE.

Hope this helps.

Pairoar answered 15/12, 2023 at 5:30 Comment(0)
B
0

In hadoop-env.cmd I changed %JAVA_HOME% to "C:\Program Files\openjdk-17_windows-x64_bin\jdk-17" with double quotation. It worked for me

set JAVA_HOME="C:\Program Files\openjdk-17_windows-x64_bin\jdk-17"

enter image description here

Brunner answered 20/6, 2023 at 12:6 Comment(0)
P
-2

in hadoop-config.xml, the logic is

if not exist %JAVA_HOME%\bin\java.exe ( echo Error: JAVA_HOME is incorrectly set. echo Please update %HADOOP_HOME%\conf\hadoop-env.cmd goto :eof )

if your java environment path contains space, such as "C:\Program Files\java\xxxxx" , the word 《Program Files》 contains a space, so CMD can't identificate

SO your can change the path instead.

Prefect answered 25/8, 2016 at 9:17 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.