hadoop为什么需要手动修改hadoop-env.sh中的JAVA_HOME?

从官网上下载的hadoop-2.8.1版本。

按照官网的教程执行sbin/start-dfs.sh命令行时,会报

localhost: Error: JAVA_HOME is not set and could not be found.

但是我已经设置了JAVA_HOME这个环境变量,也在/etc/profile中加入,但都没有起作用。

网上搜索后知道了需要手动修改hadoop-env.sh脚本。但是我觉得脚本中的写法没有问题。

通过在libexec/hadoop-config.sh输出JAVA_HOME时发现,也有能获取到JAVA_HOME的时候。

在找不到JAVA_HOME的分支条件中输出export时,发现JAVA_HOME也确实为空。

到底是什么原因导致的获取不到环境变量?

ubuntu 17.10
java 1.8.0_151-b12
hadoop-2.8.1

阅读 6.6k
2 个回答

你被国内资料误导了,/etc/profile从来都不是正确修改环境变量的姿势,甚至bash压根不会care这个文件。现在不能google,无法给你找官方文档中的内容,但还是建议你读一下linux和bash的一些英文原版资料理解下

新手上路,请多包涵

按照 profile 文件提示的样子去添加,在/etc/profile.d/目录中,添加脚本 export 环境变量

/etc/profile

System wide environment and startup programs, for login setup

Functions and aliases go in /etc/bashrc

It's NOT a good idea to change this file unless you know what you

are doing. It's much better to create a custom.sh shell script in

/etc/profile.d/ to make custom changes to your environment, as this

will prevent the need for merging in future updates.

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题