为什么我无法在MAC OS X 10.11上看到JAVA_HOME路径? [英] Why I am not able to see the JAVA_HOME path on my MAC OS X 10.11?

查看:105
本文介绍了为什么我无法在MAC OS X 10.11上看到JAVA_HOME路径?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在我的MAC OS X 10.11(El Capitan)上运行JAVA应用程序。

I am trying to run a JAVA application on my MAC OS X 10.11 ( El Capitan).

我使用了此链接在我的MAC OS X 10.11上设置JAVA_HOME。

I used this link to set the JAVA_HOME on my MAC OS X 10.11.

我可以运行以下命令:

java -version

哪个java

I am able to run the following commands:
java -version
which java

然而,当我去MAC上的终端应用程序并输入echo $ JAVA_HOME时,我什么也看不见。
为什么?
这是否意味着我的JAVA_HOME设置不正确?

However when I go to the Terminal app on MAC and type echo $JAVA_HOME, I see nothing. Why is that? Does that mean that my JAVA_HOME is not set properly ?

推荐答案

在哪里定义



好的,首先,我们必须明确 where 来设置 JAVA_HOME

简化,您可以在两个文件中定义它:〜/ .bashrc 〜/ bash_profile 。通过 default ,前者被执行用于所谓的交互式非登录shell,而后者用于登录shell。
登录shell正是您所期望的:通过命令行登录后启动的shell。 交互式非登录shell是例如从GUI内启动的shell。因此,根据这一点,我们应该将我们的出口声明放入〜/ .bashrc

Simplified, you can define it in two files: either ~/.bashrc or ~/bash_profile. By default the former is executed for what is called "interactive non-login shells" while the latter is used for "login shells". A "login shell" is exactly what you'd expect: a shell which is started after login via command line. An "interactive non-login shell" is a shell which is started from within a GUI for example. So, according to that, we should put our export statement into ~/.bashrc.

附注: OS X的终端应用程序读取所提到的两个文件,这不是默认行为,因此不应该这样对待。这就是为什么我写了一个解释。

Side note: While OS X's "Terminal" application reads both files mentioned, this is not the default behavior and therefor should not be treated as such. And thats why I wrote an explanation.

你需要在<$中导出JAVA_HOME c $ c>〜/ .bashrc 文件,以便每次打开shell时,都会设置变量。

You need to export JAVA_HOME in the ~/.bashrc file so that every time a shell is opened, the variable is set.

在OS X上, Java开发工具包和运行时环境存储在 / Library / Java / JavaVirtualMachines / 下已有一段时间了。看看那里。这是它看我的机器的方式:

On OS X, the Java Development Kits and Runtime Environments are stored under /Library/Java/JavaVirtualMachines/ for quite a while now. Have a look there. This is how it looks at my machine:

/Library/Java/JavaVirtualMachines/
├── jdk1.7.0_45.jdk
├── jdk1.8.0_20.jdk
├── jdk1.8.0_25.jdk
└── jdk1.8.0_51.jdk

子文件夹看起来类似于此

The subfolders look similar to this

jdk1.7.0_45.jdk/
└── Contents
    ├── Home
    ├── Info.plist
    └── MacOS

我们得到了它。因此,如果你想指向JDK 1.7.0_45,你可以将以下语句放入 .bashrc

And there we got it. So if you wanted to point to the JDK 1.7.0_45, you'd put the following statement into your .bashrc

export JAVA_HOME="/Library/Java/JavaVirtualMachines/jdk1.7.0_45.jdk/Contents/Home"

为了确保调用该Java版本的正确二进制文件,您还应该在上述语句之后的某处添加以下内容:

To make sure that the correct binaries for that Java version are called, you also should add the following somewhere after the above statement:

export PATH=$JAVA_HOME/bin:$PATH

这篇关于为什么我无法在MAC OS X 10.11上看到JAVA_HOME路径?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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