[linux] Hadoop: «ERROR : JAVA_HOME is not set»

I'm trying to install Hadoop on Ubuntu 11.10. I set the JAVA_HOME variable in the file conf/hadoop-env.sh to:

# export JAVA_HOME=/usr/lib/jvm/java-1.6.0-openjdk

and then I execute these commands (Standalone Operation):

$ mkdir input 
$ cp conf/*.xml input 
$ bin/hadoop jar hadoop-examples-*.jar grep input output 'dfs[a-z.]+' 
$ cat output/*

but I have the following error when executing the third command:

ERROR : JAVA_HOME is not set

Is the JAVA_HOME variable not set correctly?

This question is related to linux hadoop ubuntu-11.04

The answer is


You should set JAVA_HOME in the hadoop-env.sh file also which is in the Hadoop configuration directory. By default the JAVA_HOME setting line is commented.


Here we provide simple steps to setup JAVA_HOME while installing of Hadoop

Step1: Goto Java library path /lib jvm

Then set the JAVA_HOME & PATH in .bashrc file

Source : http://commandstech.com/hadoop-error-java_home-is-not-set-and-could-not-be-found-in-hadoop-installation/

Step 2 : Once it is done then go with Hadoop env file then update it.

After once it is done then stop the daemons and start daemons once again.


The solution that worked for me was setting my JAVA_HOME in /etc/environment

Though JAVA_HOME can be set inside the /etc/profile files, the preferred location for JAVA_HOME or any system variable is /etc/environment.

Open /etc/environment in any text editor like nano or vim and add the following line:

JAVA_HOME="/usr/lib/jvm/your_java_directory"

Load the variables:

source /etc/environment

Check if the variable loaded correctly:

echo $JAVA_HOME

I solved this in my env, without modify hadoop-env.sh

You'd be better using /bin/bash as default shell not /bin/sh

Check these before:

  1. You have already config java and env (success echo $JAVA_HOME)
  2. right config hadoop

echo $SHELL in every node, check if print /bin/bash if not, vi /etc/passwd, add /bin/bash at tail of your username ref

Changing default shell in Linux

https://blog.csdn.net/whitehack/article/details/51705889


  • hadoop ERROR : JAVA_HOME is not set

Above error is because of the space in between two words.

Eg: Java located in C:\Program Files\Java --> Space in between Program and files would cause the above problem. If you remove the space, it would not show any error.


You can add in your .bashrc file:

export JAVA_HOME=$(readlink -f /usr/bin/java | sed "s:bin/java::")

and it will dynamically change when you update your packages.


I tried the above solutions but the following worked on me

export JAVA_HOME=/usr/java/default

In some distributives(CentOS/OpenSuSe,...) will work only if you set JAVA_HOME in the /etc/environment.


Type echo $JAVA_HOME in your terminal to be sure your JAVA_HOME is set.

You can also type java -version to know what version of java you are actually using.

By the way, reading your description it seems your actually writing

export JAVA_HOME=/usr/lib/jvm/java-1.6.0-openjdk

in the file conf/hadoop-env.sh, you should write it in your terminal or in ~/.bashrc or ~/.profile then type source < path to modified file >.


I tried changing /etc/environment:

JAVA_HOME="/usr/lib/jvm/java-11-openjdk-amd64"

on the slave node, it works.


Copy this export JAVA_HOME=/usr/lib/jvm/java-1.6.0-openjdk to hadoop-env.sh file.

JAVA_HOME is the location where java binaries are present.


Make sure that you have removed the comment tag and changed your JAVA_HOME in the hadoop-env.sh as well as the appropriate .bashrc and/or .profile:

# export JAVA_HOME=/usr/lib/jvm/java-1.6.0-openjdk

should be

export JAVA_HOME=/usr/lib/jvm/java-1.6.0-openjdk

You can set your JAVA_HOME and PATH for all users (make sure you haven't previously set this to the wrong path) in /etc/profile.

Also, don't forget to activate the new change by logging-out/in or by executing source /etc/profile.


Examples related to linux

grep's at sign caught as whitespace How to prevent Google Colab from disconnecting? "E: Unable to locate package python-pip" on Ubuntu 18.04 How to upgrade Python version to 3.7? Install Qt on Ubuntu Get first line of a shell command's output Cannot connect to the Docker daemon at unix:/var/run/docker.sock. Is the docker daemon running? Run bash command on jenkins pipeline How to uninstall an older PHP version from centOS7 How to update-alternatives to Python 3 without breaking apt?

Examples related to hadoop

Hadoop MapReduce: Strange Result when Storing Previous Value in Memory in a Reduce Class (Java) What is the difference between spark.sql.shuffle.partitions and spark.default.parallelism? How to check Spark Version What are the pros and cons of parquet format compared to other formats? java.lang.RuntimeException: Unable to instantiate org.apache.hadoop.hive.ql.metadata.SessionHiveMetaStoreClient How to export data from Spark SQL to CSV How to copy data from one HDFS to another HDFS? How to calculate Date difference in Hive Select top 2 rows in Hive Spark - load CSV file as DataFrame?

Examples related to ubuntu-11.04

Python locale error: unsupported locale setting String comparison in bash. [[: not found Where is Ubuntu storing installed programs? Hadoop: «ERROR : JAVA_HOME is not set» How to run a script at the start up of Ubuntu? /etc/apt/sources.list" E212: Can't open file for writing curl : (1) Protocol https not supported or disabled in libcurl linux/videodev.h : no such file or directory - OpenCV on ubuntu 11.04