启动flink显示ERROR: JAVA_HOME is not set and could not be found.

发布时间 2023-05-09 14:19:08作者: aminor

问题:
JAVA_HOME存在,但启动flink时出现ERROR: JAVA_HOME is not set and could not be found.

原因:
环境变量加载顺序不对

# /etc/profile.d/hadoop.sh
# ...
export HADOOP_CLASSPATH=`hadoop classpath`

JAVA_HOME是在 java.sh 里定义的,而 hadoop.sh 按照字典序先于 java.sh 加载。
没有 JAVA_HOME,那么 hadoop 命令会报错。

# /etc/profile
# ...
for i in /etc/profile.d/*.sh /etc/profile.d/sh.local ; do
    if [ -r "$i" ]; then
        if [ "${-#*i}" != "$-" ]; then 
            . "$i"
        else
            . "$i" >/dev/null
        fi
    fi
done

解决:
hadoop.sh 重命名为 z1_hadoop.sh