我已经安装了从oracle网站下载的JDK 7u7。但是安装完成后,终端仍然显示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)

你知道为什么Java 7没有出现吗?

答: 好的,问题已经解决了。以下是答案: 我发现我的终端有一个.bash_profile, java主变量被设置为1.6

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

所以这就是每次我打开新终端窗口时导致问题的行。 只要去掉这条线就能解决问题。您仍然需要遵循@aleroot所说的,但如果这对您不起作用,请检查.bash_profile(或.bashrc)设置文件,以查看您之前是否导出过任何java版本。


当前回答

发生这种情况是因为.bash_profile没有反映变化。要反映它,只需使用下面的命令

$ source .bash_profile

其他回答

我认为你可以尝试安装jdk而不是jre。通过安装jdk, /usr/bin/java中的java将被替换,所有库将正常工作。

在我的案例中,问题是Oracle将它安装到与我习惯的位置不同的位置。

从Oracle下载:http://java.com/en/download/mac_download.jsp?locale=en

Verify that it's installed properly by looking in System Prefs: Command-Space to open Spotlight, type 'System Preferences', hit enter. Click Java icon in bottom row. After the Java Control Panel opens, click 'Java' tab, 'View...', and verify that your install worked. You can see a 'Path' there also, which you can sub into the commands below in case they are different than mine. Verify that the version is as you expect (sub in your path as needed): /Library/Internet\ Plug-Ins/JavaAppletPlugin.plugin/Contents/Home/bin/java -version Create link from /usr/bin/java to your new install sudo ln -fs /Library/Internet\ Plug-Ins/JavaAppletPlugin.plugin/Contents/Home/bin/java /usr/bin/java Sanity check your version: java -version

我通过重新安装优胜美地解决了这个问题,然后在终端上交叉检查java版本(java -version)和(javac -version) . it现在工作完美。它不会更改到java 7,因为版本6仍然存在于(command + n) libray>java>javavirtualmachine>您的javac当前版本。你需要地址到Java家。

你可以运行这个命令来找到/Library/Internet Plugins/下的Java版本:

defaults read /Library/Internet\ Plug-Ins/JavaAppletPlugin.plugin/Contents/Info.plist CFBundleVersion

因为我还没有面对过这个问题,我有一种预感——

你能试试这个吗:

软链接“java_home”指向哪里:

ls -lrt /usr/libexec/java_home

输出:(发育不良) lrwxr-xr-x java_home -> /System/Library/Frameworks/JavaVM.framework/Versions/Current/Commands/java_home . zip

**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

基于此,我们可能会得到进一步进行的提示?