This article is participating in “Java Theme Month – Java Debug Notes Event”, see < Event link > for more details.

** Q: Java 7 is installed on Mac OS X, but Terminal still uses Java 6? **

I have installed JDK 7 downloaded from the Oracle web site. However, after installation, the terminal still shows that the version of Java is Java 1.6

$java -versionJava 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)Copy the code

Does anyone know why Java 1.7 is not displayed?

Answer 1: Run the vi command to open the configuration file

vi ~/.bash_profile
Copy the code

Add the following:

Export JAVA_HOME = ` / usr/libexec/JAVA_HOME - 1.7 vCopy the code

This is tell you/usr/bin/Java connection target for using recently installed in the/Library/Java/JavaVirtualMachines/Java 7 packages.

So for 1.7.0 _17 version of the JDK, Java home/Library/Java/JavaVirtualMachines jdk1.7.0 _17. JDK/Contents/home

One thing to note: this part has changed a lot recently, the Java package was originally integrated on Apple’s own systems, and is now an Oracle-based Java package. The preceding solutions take effect on Mac OS X 10.8.2.

Answer 2:

For me, my problem is that Oracle installs the Java package in a different location.

After we downloaded the package from Oracle website (java.com/en/download…)

Method 1: Verify that Spotlight is installed correctly by viewing system preferences: + Open Spotlight using Command+ space, enter system preferences, press Enter to enter + Click the Java icon, when the Java Control Panel opens, click the “Java” TAB, and “View…” And verify that your installation is valid. You can also see a “path” here. If that doesn’t work, use the command line to solve your problem

Method 2: Verify that the Java version meets your expectations

/Library/Internet\ Plug-Ins/JavaAppletPlugin.plugin/Contents/Home/bin/java -version
Copy the code

Make /usr/bin/java a link to your newly installed Java

sudo ln -fs /Library/Internet\Plug-Ins/JavaAppletPlugin.plugin/Contents/Home/bin/java /usr/bin/java
Copy the code

Finally, verify the Java version

Java -version // First check the downloaded Java version, now check the default Java version.Copy the code