Linux Hadoop: ?ERROR : JAVA_HOME 未设置?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 
原文地址: http://stackoverflow.com/questions/8827102/
Warning: these are provided under cc-by-sa 4.0 license.  You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Hadoop: ?ERROR : JAVA_HOME is not set?
提问by koukou
I'm trying to install Hadoop on Ubuntu 11.10. I set the JAVA_HOMEvariable in the file conf/hadoop-env.shto: 
我正在尝试在 Ubuntu 11.10 上安装 Hadoop。我将JAVA_HOME文件中的变量设置conf/hadoop-env.sh为:
# 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
错误:未设置 JAVA_HOME
Is the JAVA_HOMEvariable not set correctly?
是JAVA_HOME不正确的变量?
回答by alain.janinm
Type echo $JAVA_HOMEin your terminal to be sure your JAVA_HOMEis set.
输入echo $JAVA_HOME您的终端,以确保您的JAVA_HOME设置。
You can also type java -versionto know what version of java you are actually using.
您还可以键入java -version以了解您实际使用的 Java 版本。
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 ~/.bashrcor ~/.profilethen type source < path to modified file >.
在文件中conf/hadoop-env.sh,您应该将其写入终端或输入~/.bashrc或~/.profile输入source < path to modified file >.
回答by user1489515
Make sure that you have removed the comment tag and changed your JAVA_HOMEin the hadoop-env.shas well as the appropriate .bashrcand/or .profile:
确保您已删除评论标签并更改您的JAVA_HOMEinhadoop-env.sh以及适当的.bashrc和/或.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_HOMEand PATHfor all users (make sure you haven't previously set this to the wrong path) in /etc/profile.
您可以设置JAVA_HOME并PATH为所有用户(请确保您之前没有将其设置为错误的路径)/etc/profile。
Also, don't forget to activate the new change by logging-out/in or by executing source /etc/profile.
另外,不要忘记通过注销/登录或执行来激活新的更改source /etc/profile。
回答by nantitv
You should set JAVA_HOMEin the hadoop-env.shfile also which is in the Hadoop configuration directory.
By default the JAVA_HOMEsetting line is commented.
您还应该JAVA_HOME在hadoop-env.shHadoop 配置目录中的文件中进行设置。默认情况下,JAVA_HOME设置行是注释的。
回答by Arun Krishnan Cp
- hadoop ERROR : JAVA_HOME is not set
- hadoop 错误:未设置 JAVA_HOME
Above error is because of the space in between two words.
以上错误是因为两个单词之间的空格。
Eg: Java located in C:\Program Files\Java--> Space in between Programand fileswould cause the above problem. If you remove the space, it would not show any error.
例如:Java 位于 C:\Program Files\Java--> Program和files之间的空间会导致上述问题。如果删除空格,则不会显示任何错误。
回答by Paulo Fidalgo
You can add in your .bashrcfile:
您可以在.bashrc文件中添加:
export JAVA_HOME=$(readlink -f /usr/bin/java | sed "s:bin/java::")
and it will dynamically change when you update your packages.
它会在您更新软件包时动态更改。
回答by American curl
Copy this export JAVA_HOME=/usr/lib/jvm/java-1.6.0-openjdkto hadoop-env.shfile. 
将此复制export JAVA_HOME=/usr/lib/jvm/java-1.6.0-openjdk到hadoop-env.sh文件中。
JAVA_HOMEis the location where java binaries are present.
JAVA_HOME是 java 二进制文件所在的位置。
回答by Ajak6
I tried the above solutions but the following worked on me
我尝试了上述解决方案,但以下对我有用
export JAVA_HOME=/usr/java/default
回答by Muthukrishnan
The solution that worked for me was setting my JAVA_HOMEin /etc/environment
对我有用的解决方案是设置我JAVA_HOME的/etc/environment
Though JAVA_HOMEcan be set inside the /etc/profile files, the preferred location for JAVA_HOMEor any system variable is /etc/environment.
虽然JAVA_HOME可以在 /etc/profile 文件中设置,但JAVA_HOME或任何系统变量的首选位置是/etc/environment.
Open /etc/environment in any text editor like nano or vim and add the following line:
在任何文本编辑器(如 nano 或 vim)中打开 /etc/environment 并添加以下行:
JAVA_HOME="/usr/lib/jvm/your_java_directory"
Load the variables:
加载变量:
source /etc/environment
Check if the variable loaded correctly:
检查变量是否正确加载:
echo $JAVA_HOME
回答by Santonio
I solved this in my env, without modify hadoop-env.sh
我在我的环境中解决了这个问题,没有修改 hadoop-env.sh
You'd be better using /bin/bashas default shell not /bin/sh
你最好不要使用/bin/bash默认 shell/bin/sh
Check these before:
之前检查这些:
- You have already config java and env (success echo $JAVA_HOME)
- right config hadoop
- 您已经配置了 java 和 env(成功echo $JAVA_HOME)
- 正确配置hadoop
echo $SHELLin every node, check if print /bin/bashif not, vi /etc/passwd, add /bin/bashat tail of your username
ref 
echo $SHELL在每个节点中,检查是否打印,/bin/bash如果没有,在用户名 ref 的尾部vi /etc/passwd添加/bin/bash
回答by nickc
In some distributives(CentOS/OpenSuSe,...) will work only if you set JAVA_HOME in the /etc/environment.
在某些发行版(CentOS/OpenSuSe,...)中,仅当您在 /etc/environment 中设置 JAVA_HOME 时才有效。

