如何在 Ubuntu 上设置 JAVA_HOME 路径? [英] How to set JAVA_HOME path on Ubuntu?
问题描述
如何设置 JAVA_HOME
路径而不必每次重新启动机器时都设置它?
How can I setup JAVA_HOME
path without having to set it each time I restart my machine?
在我的 Ubuntu 机器上尝试设置 JAVA_HOME 时,我使用了以下方法:
I've used the following ways when trying to set JAVA_HOME on my Ubuntu machine:
1) 从终端我执行了以下命令:
1) From terminal I've executed the following command:
export JAVA_HOME=/usr/lib/jvm/jdk1.7.0
2) 我直接编辑了 /etc/enviroment
文件以在其中添加 JAVA_HOME
路径
2) I've edited the /etc/enviroment
file directly to add JAVA_HOME
path in it
真正奇怪的是,如果我在上述两种方式之一之后使用 echo
命令测试 JAVA_HOME
,我可以看到它设置正确,但是如果我重新启动, 注销/重新登录,甚至在机器上工作一段时间后 JAVA_HOME
不再设置,我必须使用上述两种方式中的任何一种重新设置.
What's really strange is that if I test JAVA_HOME
using the echo
command after an of the above two ways, I can see it is set correctly, but if I restart, logout/ login again or even after working on the machine for a while the JAVA_HOME
is no more set and I have to set it again using any of the above two ways.
那么有人可以告诉我我在这里做错了什么吗?
So can someone please tell me what I am doing wrong here?
推荐答案
我通常在
~/.bashrc
但是对于 Java,我按照说明进行操作https://askubuntu.com/questions/55848/how-do-i-install-oracle-java-jdk-7
However for Java, I followed instructions at https://askubuntu.com/questions/55848/how-do-i-install-oracle-java-jdk-7
这对我来说已经足够了.
and it was sufficient for me.
你也可以定义多个 java_home 并且只有其中一个处于活动状态(其余注释).
you can also define multiple java_home's and have only one of them active (rest commented).
假设在你的 bashrc 文件中,你有
suppose in your bashrc file, you have
导出JAVA_HOME=......jdk1.7
#export JAVA_HOME=......jdk1.8
注释 1.8 已注释.一旦你这样做
notice 1.8 is commented. Once you do
source ~/.bashrc
jdk1.7 将在路径中.
jdk1.7 will be in path.
您可以通过这种方式轻松切换它们.还有其他更持久的解决方案.我发布的链接包含该信息.
you can switch them fairly easily this way. There are other more permanent solutions too. The link I posted has that info.
这篇关于如何在 Ubuntu 上设置 JAVA_HOME 路径?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!