如何在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
对我来说足够了.
您还可以定义多个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
export JAVA_HOME=......jdk1.7
#export JAVA_HOME=......jdk1.8
notice 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屋!