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_HOME
variable in the file conf/hadoop-env.sh
to:
我正在尝试在 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_HOME
variable not set correctly?
是JAVA_HOME
不正确的变量?
回答by alain.janinm
Type echo $JAVA_HOME
in your terminal to be sure your JAVA_HOME
is set.
输入echo $JAVA_HOME
您的终端,以确保您的JAVA_HOME
设置。
You can also type java -version
to 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 ~/.bashrc
or ~/.profile
then 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_HOME
in the hadoop-env.sh
as well as the appropriate .bashrc
and/or .profile
:
确保您已删除评论标签并更改您的JAVA_HOME
inhadoop-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_HOME
and PATH
for 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_HOME
in the hadoop-env.sh
file also which is in the Hadoop configuration directory.
By default the JAVA_HOME
setting line is commented.
您还应该JAVA_HOME
在hadoop-env.sh
Hadoop 配置目录中的文件中进行设置。默认情况下,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 .bashrc
file:
您可以在.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-openjdk
to hadoop-env.sh
file.
将此复制export JAVA_HOME=/usr/lib/jvm/java-1.6.0-openjdk
到hadoop-env.sh
文件中。
JAVA_HOME
is 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_HOME
in /etc/environment
对我有用的解决方案是设置我JAVA_HOME
的/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
.
虽然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/bash
as 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 $SHELL
in every node, check if print /bin/bash
if not, vi /etc/passwd
, add /bin/bash
at 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 时才有效。