如何在Mac中永久设置JAVA_HOME? [英] How to set JAVA_HOME in Mac permanently?

查看:207
本文介绍了如何在Mac中永久设置JAVA_HOME?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想通过在终端输入 export JAVA_HOME = / Library / Java / Home 来设置 JAVA_HOME
它为当前会话设置 JAVA_HOME

I am trying to set JAVA_HOME by entering export JAVA_HOME=/Library/Java/Home at terminal. It sets the JAVA_HOME for current session.

如何永久设置?

推荐答案

我知道这个问题已经有一段时间了,但我只是想分享我今天遇到的以下信息。

I know it has been a while for this question, but I just wanted to share the following piece of information that I came across today.

你可以使用 / usr / libexec / java_home -v<你想要的版本> 获取 JAVA_HOME 所需的路径。例如,要获取1.7 JDK的路径,您可以运行 / usr / libexec / java_home -v 1.7 ,它将返回JDK的路径。在您的 .profile .bash_profile 中添加

You can use /usr/libexec/java_home -v <version you want> to get the path you need for JAVA_HOME. For instance, to get the path to the 1.7 JDK you can run /usr/libexec/java_home -v 1.7 and it will return the path to the JDK. In your .profile or .bash_profile just add

export JAVA_HOME=`/usr/libexec/java_home -v <version>`

你应该好。或者,尝试并说服维护人员使用您使用此方法的java工具来获取他们需要的版本。

and you should be good. Alternatively, try and convince the maintainers of java tools you use to make use of this method to get the version they need.

要打开'.bash_profile',请输入以下内容:终端:

To open '.bash_profile' type the following in terminal :

nano ~/.bash_profile 

并将以下行添加到文件中:

and add the following line to the file:

export JAVA_HOME=`/usr/libexec/java_home -v <version>`

按CTRL + X退出bash。按'Y'保存更改。

Press CTRL+X to exit the bash. Press 'Y' to save changes.

要检查路径是否已添加,请在终端中输入以下内容:

To check whether the path has been added, type following in terminal:

source ~/.bash_profile
echo $JAVA_HOME

这篇关于如何在Mac中永久设置JAVA_HOME?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆