bash 如何在 /etc/environment 中正确设置 JAVA_HOME
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/14183934/
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
How to properly set JAVA_HOME in /etc/environment
提问by reikje
I am trying to add JAVA_HOME system-wide and also add JAVA_HOME/bin to PATH (Ubuntu 12.04). If I add the following 2 lines at the end of /etc/environment, I cannot login anymore afterwards. If I add the 2 lines to /etc/profile everything works. Wheres the problem?
我正在尝试在系统范围内添加 JAVA_HOME,并将 JAVA_HOME/bin 添加到 PATH(Ubuntu 12.04)。如果我在 /etc/environment 的末尾添加以下 2 行,之后我将无法再登录。如果我将 2 行添加到 /etc/profile 一切正常。问题出在哪里?
export JAVA_HOME="/usr/lib/jvm/java-7-oracle"
export PATH="$PATH:$JAVA_HOME/bin"
There is already the following line in /etc/environment (line 1):
/etc/environment 中已经有以下行(第 1 行):
PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games"
回答by CerealKiller
Just write
写就好了
JAVA_HOME="/usr/lib/jvm/java-7-oracle"
on your /etc/environment, without the "export"
在您的 /etc/environment 上,没有“导出”
回答by Quentin
/etc/environmentis supposed to contain a set of environment variables given as key=value pairs. It is not a shell script, so you can't use shell commands such as exportin it.
/etc/environment应该包含一组作为键=值对给出的环境变量。它不是 shell 脚本,因此您不能在其中使用 shell 命令export。

