Working With Hadoop: localhost: Error: JAVA_HOME is not set
Asked Answered
O

12

31

I'm working with Ubuntu 12.04 LTS.

I'm going through the hadoop quickstart manual to make a pseudo-distributed operation. It seems simple and straightforward (easy!).

However, when I try to run start-all.sh I get:

localhost: Error: JAVA_HOME is not set.

I've read all the other advice on stackoverflow for this issue and have done the following to ensure JAVA_HOME is set:

In /etc/hadoop/conf/hadoop-env.sh I have set

JAVA_HOME=/usr/lib/jvm/java-6-oracle
export JAVA_HOME

In /etc/bash.bashrc I have set

JAVA_HOME=/usr/lib/jvm/java-6-oracle
export JAVA_HOME
PATH=$PATH:$JAVA_HOME/bin
export PATH

which java returns:

/usr/bin/java

java –version works

echo $JAVA_HOME returns:

/usr/lib/jvm/java-6-oracle

I've even tried becoming root and explicitly writing the in the terminal:

$ JAVA_HOME=/usr/lib/jvm/java-6-oracle
$ export JAVA_HOME
$ start-all.sh

If you could show me how to resolve this error it would be greatly appreciated. I'm thinking that my JAVA_HOME is being overridden somehow. If that is the case, could you explain to me how to make my exports global?

Obstinacy answered 14/1, 2013 at 19:52 Comment(1)
When you change your bashrc you need to reset the terminalTremulous
A
71

I am using hadoop 1.1, and faced the same problem.

I got it solved through changing JAVA_HOME variable in /etc/hadoop/hadoop-env.sh as:

export JAVA_HOME=/usr/lib/jvm/<jdk folder>
Ailis answered 14/1, 2013 at 19:52 Comment(6)
Yes, this was the case. It also works for hadoop-2.6.0. Thanks!Deutsch
Works for hadoop-2.7.3Timotheus
Works for hadoop-3.0Giant
Works still for hadoop in year 3038Euphuism
Works in 2021, but my localhost still doesn't run.Lite
Worked for 3.3.4Claraclarabella
H
21

The way to solve this problem is to export the JAVA_HOME variable inside the conf/hadoop-env.sh file.

It doesn't matter if you already exported that variable in ~/.bashrc, it'll still show the error.

So edit conf/hadoop-env.sh and uncomment the line "export JAVA_HOME" and add a proper filesystem path to it, i.e. the path to your Java JDK.

# The Java implementation to use. Required.
export JAVA_HOME="/path/to/java/JDK/"

Haruspicy answered 28/6, 2013 at 13:14 Comment(3)
I also had to set it explicitly, not as ${JAVA_HOME}Blank
@NikitaG. So do I. Even when i echo ${JAVA_HOME} always print the correct value, only set it explicitly works.Tartrazine
in hadoop-2.7.3, the hadoop-env.sh file is located in hadoop-2.7.3/etc/hadoop directory instead of the conf directoryCassiecassil
O
4

Ran into the same issue on ubuntu LTS 16.04. Running bash -vx ./bin/hadoop showed it tested whether java was a directory. So I changed JAVA_HOME to a folder and it worked.

++ [[ ! -d /usr/bin/java ]]
++ hadoop_error 'ERROR: JAVA_HOME /usr/bin/java does not exist.'
++ echo 'ERROR: JAVA_HOME /usr/bin/java does not exist.'
ERROR: JAVA_HOME /usr/bin/java does not exist.

So I changed JAVA_HOME in ./etc/hadoop/hadoop-env.sh to

export JAVA_HOME=/usr/lib/jvm/java-8-oracle/jre/

and hadoop starts fine.

Oecology answered 10/5, 2018 at 16:34 Comment(0)
A
1

The way to debug this is to put an "echo $JAVA_HOME" in start-all.sh. Are you running your hadoop environment under a different username, or as yourself? If the former, it's very likely that the JAVA_HOME environment variable is not set for that user.

The other potential problem is that you have specified JAVA_HOME incorrectly, and the value that you have provided doesn't point to a JDK/JRE. Note that "which java" and "java -version" will both work, even if JAVA_HOME is set incorrectly.

Analiese answered 14/1, 2013 at 20:34 Comment(1)
Thanks. I was running it as Root at the time (to avoid permission issues) and it was overriding my JAVA_HOME. I ended up making a new user and giving it the right permissions. The Bash.Bashrc worked with the new username. Everything is great now [ as in new to solve :) ]Obstinacy
R
1

extract from etc/hadoop/hadoop-env.sh

The only required environment variable is JAVA_HOME. All others are optional. When running a distributed configuration it is best to set JAVA_HOME in this file, so that it is correctly defined on remote nodes.

This means its better and advised to set JAVA_HOME here.. even though the existing definition reads the JAVA_HOME variable. Perhaps its not getting the value of JAVA_HOME from previously set value... standard apache manual does not tell this :( :(

Rola answered 16/12, 2015 at 21:29 Comment(0)
E
1

This error is coming from Line 180

if [[ -z $JAVA_HOME ]]; then
   echo "Error: JAVA_HOME is not set and could not be found." 1>&2
   exit 1
fi

in libexec/hadoop-config.sh.

Try echo $JAVA_HOME in that script. If it doesn't recognize,

Find your JAVA_HOME using this:

$(readlink -f /usr/bin/javac | sed "s:/bin/javac::")

and replace the line

export JAVA_HOME=${JAVA_HOME} in /etc/hadoop/hadoop-env.sh with JAVA_HOME you got from above command.

Enfranchise answered 20/12, 2016 at 8:42 Comment(0)
S
1

I also had faced the similar problem in hadoop 1.1 I had not noticed that the JAVA_HOME was commented in: hadoop/conf/hadoop-env.sh

It was

/#JAVA_HOME=/usr/lib/jvm/java-6-oracle

Had to change it to

JAVA_HOME=/usr/lib/jvm/java-6-oracle
Satinwood answered 26/10, 2017 at 9:5 Comment(1)
I was facing the same,Aubade
A
1

regardless of debian or any linux flavor, just know that ~/.bash_profile belongs to specific user and is not system wide. in pseudo-distributed environment hadoop works on localhost so the $JAVA_HOME in .bash_profile is no use anymore.

just export the JAVA_HOME in ~/.bashrc and use it system wide.

Aerification answered 2/12, 2017 at 23:18 Comment(0)
S
0

Check if your alternatives is pointing to the right one, you might actually be pointing to a different version and trying to alter the hadoop-env.sh on another installed version.

-alternatives --install /etc/hadoop/conf [generic_name] [your correct path] priority {for further check man page of alternatives}

to set alternatives manually,

alternatives --set [generic name] [your current path].

Sharpeyed answered 19/1, 2016 at 0:7 Comment(0)
L
0

Change the JAVA_HOME variable in conf/hadoop-env.sh

export JAVA_HOME=/etc/local/java/<jdk folder>
Lineberry answered 13/4, 2016 at 14:33 Comment(1)
Could you please elaborate more your answer adding a little more description about the solution you provide?Jaala
M
0
echo "export JAVA_HOME=/usr/lib/java" >> $HADOOP_HOME/etc/hadoop/hadoop-env.sh

Notice: Do not use export JAVA_HOME=${JAVA_HOME} !

Miseno answered 3/11, 2016 at 16:7 Comment(0)
D
-1

I put it on the first line of file ~/.bashrc, then it works well!

export JAVA_HOME=/usr/lib/jvm/default-java

Denumerable answered 21/4, 2021 at 10:17 Comment(1)
This did not work for me.Claraclarabella

© 2022 - 2024 — McMap. All rights reserved.