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

查看:29
本文介绍了如何在 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.

如何永久设置?

推荐答案

您可以使用 /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天全站免登陆