欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

在Mac OS X上安装了Java 7但终端仍在使用版本6

程序员文章站 2022-04-22 12:09:03
...

本文翻译自:Installed Java 7 on Mac OS X but Terminal is still using version 6

I've installed JDK 7u7 downloaded from oracle's website. 我安装了从oracle网站下载的JDK 7u7。 But after installation, the terminal is still showing java version 6 但安装后,终端仍然显示java版本6

$java -version
java version "1.6.0_35"
Java(TM) SE Runtime Environment (build 1.6.0_35-b10-428-11M3811)
Java HotSpot(TM) 64-Bit Server VM (build 20.10-b01-428, mixed mode)

any idea why java 7 is not showing up? 任何想法为什么java 7没有出现?

Ans: OK, the problem has been resolved. Ans:好的,问题已经解决了。 Here is the answer: I found that my Terminal has a .bash_profile and the java home variable is set to 1.6 答案是:我发现我的终端有一个.bash_profile,java home变量设置为1.6

export JAVA_HOME="/System/Library/Frameworks/JavaVM.framework/Versions/1.6.0/Home"

So this is the line causing the problem every time I opened a new terminal window. 因此,每次打开新的终端窗口时,这都会导致问题。 Simply remove this line will solve the problem. 只需删除此行即可解决问题。 You still need to follow what @aleroot said, but if that doesn't work for you, check the .bash_profile (or .bashrc) setting file to see if you've previously exported any java version. 您仍然需要遵循@aleroot所说的内容,但如果这对您不起作用,请检查.bash_profile(或.bashrc)设置文件以查看您之前是否已导出任何Java版本。


#1楼

参考:https://stackoom.com/question/rWp4/在Mac-OS-X上安装了Java-但终端仍在使用版本


#2楼

Because you need to enter in Java Preferences pane and flag only the JVM 7 in this way : 因为您需要输入Java Preferences窗格并以这种方式仅标记JVM 7:

在Mac OS X上安装了Java 7但终端仍在使用版本6

To easily and quickly open the Java Preferences pane in Mac OS X you can simply call spotlight with + SPACE and type System Preferences it will show up in the last row of the window. 要在Mac OS X中轻松快速地打开“ Java首选项”窗格,您只需使用 + SPACE调用聚光灯,然后键入系统首选项 ,它将显示在窗口的最后一行。


#3楼

http://www.java.com/en/download/faq/java_mac.xml是个理解的好地方,而Apple正在停止对Java的支持,为什么Java Preferences不再存在并且依赖于System_Preferences => Java = >如果安装了Oracle的Java 7,则为Java。


#4楼

I had run into a similar issue with terminal not updating the java version to match the version installed on the mac. 我遇到了类似的问题,终端没有更新java版本以匹配mac上安装的版本。

There was no issue with the JAVA_HOME environmental variable being set 设置JAVA_HOME环境变量没有问题

I have come up with a temporary and somewhat painful but working solution. 我想出了一个暂时的,有点痛苦但有效的解决方案。

In you .bash_profile add the line: 在你.bash_profile中添加以下行:

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

(This is the path on my machine but may be different on yours, make sure to get yours. The paths should match up to /Library/Java/JavaVirtualMachines/) (这是我的机器上的路径,但可能与您的路径不同,请确保获取您的路径。路径应匹配/ Library / Java / JavaVirtualMachines /)

the run source ~/.bash_profile 运行source ~/.bash_profile

As I mentioned this is a temporary band-aid solution because the java home path is being hard-coded. 正如我所提到的,这是一个临时的创可贴解决方案,因为java主路径是硬编码的。 There is really no way to set the path to get the latest as that is what Apple is supposedly doing for terminal already and the issue is that Apple's java_home environment variable is not getting updated. 实际上没有办法设置获取最新版本的路径,因为苹果应该已经为终端做了什么,问题是Apple的java_home环境变量没有得到更新。


#5楼

Hard-coding the JAVA_HOME path might not be the best idea. 对JAVA_HOME路径进行硬编码可能不是最好的选择。 The /usr/libexec/java_home utility sill works for me on Mac OSX Lion 10.7.5 and JDK 1.7.0_13. /usr/libexec/java_home实用程序在Mac OSX Lion 10.7.5和JDK 1.7.0_13上适用于我。 According to its man page, it is meant to be used with Apple's old Java Preferences pane, but it appears to be working with the replacement provided by Oracle (Java Control Panel). 根据其手册页,它可以与Apple旧的Java Preferences窗格一起使用,但它似乎与Oracle(Java控制面板)提供的替代品一起使用。 For example running /usr/libexec/java_home -V lists all installed JDKs (both 1.6.* and 1.7.*) on my machine. 例如,运行/usr/libexec/java_home -V在我的机器上列出所有已安装的JDK(1.6。*和1.7。*)。

So, as discussed in other threads (eg What should I set JAVA_HOME to on OSX ), I would still recommend adding the following line to your .bash_profile: 因此,正如其他线程中所讨论的(例如, 我应该在OSX上设置JAVA_HOME应该怎么做 ),我仍然建议在.bash_profile中添加以下行:

export JAVA_HOME=$(/usr/libexec/java_home)

#6楼

Since i have not faced this issue , I am taking a hunch -- 由于我没有遇到这个问题,我正在采取预感 -

Can you please try this : 你能试试这个:

Where does the soft link "java_home" point to : 软链接“java_home”指向哪里:

ls -lrt /usr/libexec/java_home

Output : (Stunted) lrwxr-xr-x java_home -> /System/Library/Frameworks/JavaVM.framework/Versions/Current/Commands/java_home 输出:( Stunted)lrwxr-xr-x java_home - > /System/Library/Frameworks/JavaVM.framework/Versions/Current/Commands/java_home

**ls -lrt /System/Library/Frameworks/JavaVM.framework/Versions My MAC Produces the following : ** ls -lrt /System/Library/Frameworks/JavaVM.framework/Versions我的MAC产生以下内容:

 lrwxr-xr-x CurrentJDK ->
 /System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents**

 lrwxr-xr-x   Current -> A
 lrwxr-xr-x  1 root  wheel   10 Oct 18 14:39 1.6.0 -> CurrentJDK
 lrwxr-xr-x  1 root  wheel   10 Oct 18 14:39 1.6 -> CurrentJDK
 lrwxr-xr-x  1 root  wheel   10 Oct 18 14:39 1.5.0 -> CurrentJDK
 lrwxr-xr-x  1 root  wheel   10 Oct 18 14:39 1.5 -> CurrentJDK
 lrwxr-xr-x  1 root  wheel   10 Oct 18 14:39 1.4.2 -> CurrentJDK
 lrwxr-xr-x  1 root  wheel   10 Oct 18 14:39 1.4 -> CurrentJDK

Based on this , we might get a hint to proceed further ? 基于此,我们可能会得到进一步的提示吗?

相关标签: java macos java-7