如何在/etc/environment中正确设置JAVA_HOME

时间:2022-12-17 23:08:05

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/bin并向PATH (Ubuntu 12.04)添加JAVA_HOME/bin。如果我在/etc/environment的末尾添加以下两行,之后就不能再登录了。如果我将这两行添加到/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"

2 个解决方案

#1


12  

Just write

只写

JAVA_HOME="/usr/lib/jvm/java-7-oracle"

on your /etc/environment, without the "export"

在您的/etc/环境中,没有“导出”

#2


9  

/etc/environment is 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 export in it.

/etc/environment应该包含一组给定的环境变量,作为键=值对。它不是shell脚本,所以不能在其中使用shell命令,比如export。

#1


12  

Just write

只写

JAVA_HOME="/usr/lib/jvm/java-7-oracle"

on your /etc/environment, without the "export"

在您的/etc/环境中,没有“导出”

#2


9  

/etc/environment is 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 export in it.

/etc/environment应该包含一组给定的环境变量,作为键=值对。它不是shell脚本,所以不能在其中使用shell命令,比如export。