问题描述
如何设置 JAVA_HOME
路径,而不必在每次重启机器时设置它?
How can I setup JAVA_HOME
path without having to set it each time I restart my machine?
I尝试在我的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?
推荐答案
我通常会拍拍hs in
I normally set paths in
~/.bashrc
但对于Java,我按照
的说明
However for Java, I followed instructions athttps://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
通知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路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!