我已经安装了从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版本。
Oracle的安装程序将java放在/Library/Internet plug - in /JavaAppletPlugin.plugin中。它不会覆盖/usr/bin/java.所以,如果你发行一个
whereis java
在终端中,它将返回/usr/bin/java.(反过来指向/System/Library/Frameworks/JavaVM.framework/Versions/A/Commands/java,这是苹果的1.6版本)。
所以,如果你想使用新的java版本,替换/usr/bin/java符号链接,使其指向/Library/Internet\ Plug-Ins/JavaAppletPlugin。插件/内容/ Home / bin / java相反:
sudo rm /usr/bin/java
sudo ln -s /Library/Internet\ Plug-Ins/JavaAppletPlugin.plugin/Contents/Home/bin/java /usr/bin
在我的案例中,问题是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