JAVA _Home is not set in Hadoop - java

I am a beginner with hadoop and trying to install and run hadoop in my Ubuntu as a single node cluster. This is my JAVA_HOME in my hadoop_env.sh
# The java implementation to use.
export JAVA_HOME=/usr/lib/jvm/java-7-openjdk-i386/
export HADOOP_CONF_DIR=${HADOOP_CONF_DIR:-"/etc/hadoop"}
But when I run it the following errors come-
Starting namenodes on [localhost]
localhost: Error: JAVA_HOME is not set and could not be found.
localhost: Error: JAVA_HOME is not set and could not be found.
Starting secondary namenodes [0.0.0.0]
0.0.0.0: Error: JAVA_HOME is not set and could not be found.
How do I remove this error?

I debugged the code and found out that even though JAVA_HOME is set in the environment, the value is lost as ssh connections to other hosts is made inside the code, and the JAVA_HOME variable that was showing well set in start-dfs.sh became unset in hadoop-env.sh.
The solution to this problem will be to set JAVA_HOME variable in hadoop-env.sh and it should work properly.

I had the same error and solved it with Soil Jain's remark, but to make it even a bit more clear: the hadoop-env.sh uses an expression such as
export JAVA_HOME=${JAVA_HOME}
if you hard-code the path to your JVM installation it works
export JAVA_HOME=/usr/lib/jvm/java...
this resolution by environmental variable as is seems to fail. Hard-coding fixed the problem for me.

Under your HADOOP_HOME/conf directory please update the hadoop-env.sh file. It has entry to export JAVA_HOME.
Setting to appropriate JAVA_HOME in this file should solve your issue.

Are you loading hadoop_env.sh? you may be refering to hadoop-env.sh ( dash instead of underscore - that is under conf directory)
BTW, This is a very useful guide for quick installation :
http://www.michael-noll.com/tutorials/running-hadoop-on-ubuntu-linux-single-node-cluster/

First, you must set JAVA_HOME in your hadoop_env.sh . (your local JAVA_HOME in .bashrc would likely to be ignore somehow)
# The java implementation to use.
export JAVA_HOME=/usr/lib/jvm/default-java
Then, set HADOOP_CONF_DIR point to directory of your hadoop_env.sh . In ~/.bashrc, add the following line:
HADOOP_CONF_DIR="/usr/local/hadoop/etc/hadoop"
export HADOOP_CONF_DIR
Where /usr/local/hadoop/etc/hadoop is the directory contained hadoop_env.sh

I'm using hadoop 2.8.0. Even though I exported JAVA_HOME (I put it in .bashrc), I still caught this error while trying to run start-dfs.sh.
user#host:/opt/hadoop-2.8.0 $ echo $JAVA_HOME
<path_to_java>
user#host:/opt/hadoop-2.8.0 $ $JAVA_HOME/bin/java -version
java version "1.8.0_65"
...
user#host:/opt/hadoop-2.8.0 $ sbin/start-dfs.sh
...
Starting namenodes on []
localhost: Error: JAVA_HOME is not set and could not be found.
localhost: Error: JAVA_HOME is not set and could not be found.
The only way I could get it to run was to add JAVA_HOME=path_to_java to etc/hadoop/hadoop-env.sh and then source it:
:/opt/hadoop-2.8.0 $ grep JAVA_HOME etc/hadoop/hadoop-env.sh
#export JAVA_HOME=${JAVA_HOME}
export JAVA_HOME=path_to_java
user#host:/opt/hadoop-2.8.0 $ source etc/hadoop/hadoop-env.sh
Maybe that (sourcing hadoop-env.sh) was implied in the posts above. Just thought someone should say it out loud. Now it runs. I've encountered other issues (due, I suspect, to the limited resources on the server I'm using), but at least I got past this one.

Above answers should work as long as you are using default conf directory $HADOOP_HOME/conf or $HADOOP_HOME/etc/hadoop. Here are a few things you should do if you're using a different conf folder.
Copy the hadoop-env.sh file from the default conf directory to your conf folder, say /home/abc/hadoopConf.
Replace the line
#export JAVA_HOME=${JAVA_HOME}
with the following:
export JAVA_HOME=/usr/lib/jvm/java-8-oracle
export HADOOP_CONF_DIR=/home/abc/hadoopConf
Change the values appropriately. If you have any other environment variables related to hadoop configured in your .bashrc or .profile or .bash_profile consider adding them next to the above lines.

It not know space between Program and Files: "Program Files".
So, I copy folder of jdk to C: or folder which not contains space in name of folder and assign: export JAVA_HOME=Name_Path_Copied. I see it run ok

Related

How to upgrade JDK from Oracle to Zulu in redhat linux

I want to upgrade my Linux JDK from Oracle to Azul-Zulu.can someone helps me to do this.
What to do after downloading the tar.gz Zulu package?
I see that after extracting the downloaded package we need to put it in the path where we need to access java. Is that correct or what we can do more like setting environment variables etc.
the answer to your question depends on what you actually want to start with the JDK. Sometimes is is sufficient to change the path to java binary in a start script, e.g. Eclipse or Tomcat, sometimes you also need to setup the variable JAVA_HOME.
To setup the java for yourself only:
Check your shell by running echo $SHELL
-> /bin/bash
-> /bin/zsh
-> /bin/tcsh
or something like that Locate your shell's config file:
bash: ~/.bashrc
zsh: ~/.zshrc
tcsh: ~/.cshrc or ~/.tcshrc
and optionally most of the shells: ~/.profile or ~/.login check those file(s) if you already have variable declarations for: JAVA_HOME JRE_HOME (and rarely seen) SDK_HOME JDK_HOME
check whether any of those files contain a setup for the variable PATH (probably has)
If you found any of the *_HOME variables from above you can change them to reflect your new java home directory: e.g. zulu11.37.17-ca-jdk11.0.6-linux_x64 located under /opt/zulu11.37.17-ca-jdk11.0.6-linux_x64 would mean to set the variables as follows: zsh and bash:
export JAVA_HOME=/opt/zulu11.37.17-ca-jdk11.0.6-linux_x64
export JRE_HOME=/opt/zulu11.37.17-ca-jdk11.0.6-linux_x64
tcsh
setenv JAVA_HOME /opt/zulu11.37.17-ca-jdk11.0.6-linux_x64
setenv JRE_HOME /opt/zulu11.37.17-ca-jdk11.0.6-linux_x64
SDK_HOME and JDK_HOME may point to the above locations as well but are normally unused.
If you located your PATH somewhere it may read something like this: zsh and bash:
export PATH=~/bin:$PATH
tcsh:
setenv PATH ~/bin:$PATH
In order for your new java to appear "before" the "other" java you need to update (or create if missing) this to e.g.: zsh and bash:
export PATH=~/bin:/opt/zulu11.37.17-ca-jdk11.0.6-linux_x64/bin:$PATH
tcsh:
setenv PATH ~/bin:/opt/zulu11.37.17-ca-jdk11.0.6-linux_x64/bin:$PATH
After completely logging out and in again your JAVA_HOME and PATH can be controlled in a shell like this:
echo $JAVA_HOME -> should point to *your* java folder
echo $PATH -> should contain *your* java folder's bin directroy
which java -> should list the new java binary instead of /bin/java or /usr/bin/java
BTW: the variables JAVA_HOME, JRE_HOME and PATH may also be set in a startscript, e.g. catalina.sh for tomcat or the eclipse.ini for eclipse if you do not want to modify your environment.
If you download the RPM/DEB instead of the tar.gz and install the package you (may) not need configure anything since the packages might re-configure your system for you
Cheers, Holger

Windows 10 Gradle: JAVA_HOME is set to an invalid directory

I was trying to run ./gradlew bootRun in both Git Bash and PowerShell, and got this error: ERROR: JAVA_HOME is set to an invalid directory: C:\Program Files\Java\jre1.8.0_121
The gradlew file is inside the project directory that cloned from git. It is a practice project from Spring official guide. There's also a gradle.bat file with these lines:
:findJavaFromJavaHome
set JAVA_HOME=%JAVA_HOME:"=%
set JAVA_EXE=%JAVA_HOME%\bin\java.exe
I also tried to run Eclipse EE, which got no problem. The environment setting should be no problem.
In addition to Ernest's answer, the JAVA_HOME it wants is the actual directory, not the bin folder like the path wants for javac. Took me a while to work that out
Looks like your JAVA_HOME variable resolves to a JRE installation directory. But as you're talking about Gradle, you're surely trying to build/compile code.
If you have a JDK installed, change JAVA_HOME variable to point to it. The folder name should typically start with "jdk". Otherwise, you have to install a Java Development Kit.
You could also try exporting the variable manually before running gradle on the command line (SET JAVA_HOME=<path to the jdk directory>)
Please set the JAVA_HOME variable location to the path to JDK instead of JRE.
If that is correctly set, check the environment variables in Edit mode.
In my case, I found that a semicolon was appended to the JAVA_HOME environment variable at the end.
To check:
Open the environment variables list.
Select the variable and click Edit.
Remove the semicolon and Save.
Closed the settings and checked the path in cmd using echo %JAVA_HOME%, and ran gradle -v.
It ran perfectly.
Note: Check the variable value by clicking the Edit button as we cannot see the semicolon instead. Windows adds a semicolon so that the same variable can be used as the path to multiple locations.
Added picture for reference:
Found a solution I hadn't seen before in my googling.
Open up your gradlew.bat in some editor. On line 34-ish you will see this:
:findJavaFromJavaHome
set JAVA_HOME=%JAVA_HOME:"=%
set JAVA_EXE=%JAVA_HOME%\bin\java.exe
if exist "%JAVA_EXE%" goto init
echo.
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
echo.
echo Please set the JAVA_HOME variable in your environment to match the
echo location of your Java installation.
add this line to the error message: echo %JAVA_EXE%
so it looks like this
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
echo %JAVA_EXE%
echo.
echo Please set the JAVA_HOME variable in your environment to match the
echo location of your Java installation.
Then run your gradlew.bat file.
The error should now appear again, but with the added echo of the path to JAVA_EXE. In my case it was echoing \bin\java.exe and NOT the full path C:\...\Java\jre1.8.0_251\bin\java.exe
to fix this, I changed
set JAVA_EXE=%JAVA_HOME%\bin\java.exe
to
set JAVA_EXE=C:\...\Java\jdk1.8.0_261\bin\java.exe
The value is now hardcoded, true, but it worked. I don't know why gradle doesn't concat the variable name into the path.
I've found myself with the same issue, although my JAVA_HOME was set to the correct JDK path.
However Windows 10 appended a semicolon at the end of the path.
This way the JAVA_HOME variable would work anywhere but not with Gradle.
I'm posting this, because it might spare someone else the time I've been looking for it ;)
If you didn't have admin rights, override the JAVA_HOME in User Environment Variable. Avoid typo by selecting the Java home folder. You must include folder before the bin ( do not include /bin) for java home.
If none of the above works open the gradle.bat file in an editor and make sure that IT is correct , in my case gradle was the problem

Not able to set JAVA_HOME variable in ubuntu 14.04 on manual installation

I've downloaded java jdk1.8.0.7.tar.gz file from the official website and unzipped it into my home directory. Now to set the $JAVA_HOME variable I used the follwing commands command nano .bashrc and then appending export $JAVA_HOME=/home/shivam/Java/jdk1.8.0.7 at the end of the file . But whenever I run the command sudo $CATALINA_HOME/bin/startup.sh I get an error message saying
Neither the JAVA_HOME nor the JRE_HOME environment variable is defined
At least one of these environment variable is needed to run this program
I don't understand why it is unable to find the java path though I've installed tomcat and set its home variable the this way, which worked.
I wan't to install Java manually without using apt-get. Kindly guide .
You want to append the following to .bashrc:
JAVA_HOME=/home/shivam/Java/jdk1.8.0.7
Note the missing $ at the start.
Also remember that the file won't effect your current shell without sourceing it first.
Also, when running a command with sudo, you are running it as the root user, not as yourself. So the environment variable needs to be set for the root user, not yourself.
You can run sudo env | grep JAVA_HOME to see whether it is set for root.
Have you run .bashrc ?
source .bashrc
Try add the following 2 lines in your .bashrc file:
JAVA_HOME=/home/shivam/Java/jdk1.8.0.7/
export JAVA_HOME

JAVA path error in hadoop

I installed hadoop watching a youtube video.
while I try to run this in terminal it gives me this error
$ /usr/local/hadoop-2.6.0/bin/hadoop version
/usr/local/hadoop-2.6.0/bin/hadoop: line 144: /usr/iib/java/jdk1.8.0_31/bin//bin/java: No such file or directory
I have java in /usr/lib/java/jdk1.8.0_31/bin/ but I dont know why the error is showing a different path.
I have setup the path in hadoop-env.sh like this
JAVA_HOME=/usr/iib/java/jdk1.8.0_31/bin/
export JAVA_HOME=${JAVA_HOME}
I did the same in .bashrc
export HADOOP_HOME=/usr/local/hadoop-2.6.0/bin/hadoop
JAVA_HOME=/usr/iib/java/jdk1.8.0_31/bin
export JAVA_HOME
PATH=$PATH:$JAVA_HOME
export PATH
Please help me. if you need any extra info please ask.
Your JAVA_HOME should point to /usr/iib/java/jdk1.8.0_31 and not the bin folder under it.
Also, usually it would be lib and not iib.
The PATH should include the $JAVA_HOME/bin, though.
You need to change JAVA_HOME from:
JAVA_HOME=/usr/iib/java/jdk1.8.0_31/bin/
TO
JAVA_HOME=/usr/iib/java/jdk1.8.0_31
i.e. Remove bin directory from JAVA_HOME variable.
And change PATH from:
PATH=$PATH:$JAVA_HOME
TO
PATH=$PATH:$JAVA_HOME/bin
Ok. I saw you problem.you may be no install jdk or your jdk's path is wrong.
now you can test it :
test you jdk location: whereis java
found your path and type it:export JAVA_HOME=/usr/iib/java/jdk1.8.0_31/
export JRE_HOME=/usr/iib/java/jdk1.8.0_31
export CLASSPATH=.:$JAVA_HOME/lib:$JRE_HOME/lib:$ClASSPATH
export PATH=$JAVA_HOME/bin:$JRE_HOME/bin:$PATH
done it .Then you type hadoop path
all type in ~/.bashrc

"JAVA_HOME points to an invalid Java installation issue" with service install command in elastic search

I want to use elastic search with my PHP application.
after running service install command , I am getting fallowing error.
C:\elasticsearch-0.90.10\bin>service install
JAVA_HOME points to an invalid Java installation (no java.exe found in "C:\Progr
am Files (x86)\Java\jdk1.7.0_25\bin"). Existing...
Open up and Look into the service.bat file:
It searches for:
%JAVA_HOME%\bin\java.exe
hence your %JAVA_HOME% should not include bin in it.
A workaround if you do not have privileges to set up the environmental variables:
open the service.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
Note: This is just a workaround which works all the time.
from your error message we can see your JAVA_HOME points to
C:\Program Files (x86)\Java\jdk1.7.0_25\bin
while it should point to
C:\Program Files (x86)\Java\jdk1.7.0_25
I think the error message is fairly descriptive , you should look in this folder
is java.exe there ? If not then your JAVA_HOME environment variable to point to the correct installation
heres a page showing how to do that
https://confluence.atlassian.com/display/DOC/Setting+the+JAVA_HOME+Variable+in+Windows
1st hit on google.
Either JAVA_HOME points to the wrong location or you don't have Java installed. Check and see if there's an install of Java in the location specified.
Also note that the JAVA_HOME variable should point to the root of the Java install not the /bin folder. This is being added by the program you're executing.
To change the JAVA_HOME variable to test further use the following in the command prompt:
set JAVA_HOME=c:\xxxx
Once you've established the correct value to use this can be permanently changed in Control Panel>>System>>Advanced System Settings>>Advanced>>Environment Variables
set JAVA_HOME=C:\Program Files (x86)\Java
Above must fix the issue, I came across the same issue while installing the elastic search.
i gave a try by giving "bin" part of path but it did not work, so i just give the top folder "java" in path, it worked.
Just to add my own experience.
i was setting JAVA_HOME using tab autocompletion.
It ends up something like "C:\Program files...:" and it didn't work saying that it cannot find the java program. I solved typing the JAVA_HOME path in the set command without using tab completion. The problem was probably related to the " in the env variable

Categories

Resources