Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

After upgrading to Java8, javac still shows 1.7

Tags:

java

macos

java-8

I'm having issues upgrading from JDK 1.7 -> 1.8 on OSX. The upgrade has completed, but javac still returns 1.7 as the version.

I've downloaded JDK 8_u5 from Oracle's homepage, and run the installer.

I've also taken the following steps, post-install:

> export JAVA_HOME=`/usr/libexec/java_home -v 1.8`  (Executed in my .bashrc file)  > echo $JAVA_HOME /Library/Java/JavaVirtualMachines/jdk1.8.0_05.jdk/Contents/Home  > javac -version javac 1.7.0_21  > $JAVA_HOME/bin/javac -version javac 1.7.0_21  > $JAVA_HOME/bin/java -version     java version "1.8.0_05" Java(TM) SE Runtime Environment (build 1.8.0_05-b13) Java HotSpot(TM) 64-Bit Server VM (build 25.5-b02, mixed mode) 

I've gone through and removed Java 1.7 (and all other JDK versions), and then re-run the installer:

> ls /Library/Java/JavaVirtualMachines jdk1.8.0_05.jdk 

Still no use, javac reports the version as 1.7.0_21

> which javac /usr/bin/javac  > ls -ltra /usr/bin/javac  [snipped] /usr/bin/javac -> /System/Library/Frameworks/JavaVM.framework/Versions/Current/Commands/javac 

Within that path, Current is a symlink to A. The contents of A/Commands are a series of files (not symlinks).

> cd A/Commands > ./javac -version javac 1.7.0_21  > ./java -version java version "1.8.0_05" Java(TM) SE Runtime Environment (build 1.8.0_05-b13) Java HotSpot(TM) 64-Bit Server VM (build 25.5-b02, mixed mode) 

Edit

Further to the original post, I've done some digging with jenv, as suggested on this answer.

> jenv add /Library/Java/JavaVirtualMachines/jdk1.8.0_05.jdk/Contents/Home                  > jenv global oracle64-1.8.0.05 > jenv version oracle64-1.8.0.05 (set by /Users/martypitt/.jenv/version)  > jenv info java  Jenv will exec : /Users/martypitt/.jenv/versions/oracle64-1.8.0.05/bin/java  > jenv info javac Jenv will exec : /Users/martypitt/.jenv/versions/oracle64-1.8.0.05/bin/javac  > javac -version javac 1.7.0_21 

This casts dispersions on my thoughts that this was a random javac lurking in my path, which was somehow getting invoked.

To be sure, I've nuked my Java completely, and tried again:

> cd /Library/Java/JavaVirtualMachines > ls  jdk1.7.0_55.jdk  jdk1.8.0_05.jdk > sudo rm -rf *   > ls <<empty>> > java -version java version "1.6.0_65" > javac -version javac 1.6.0_65 > which javac /usr/bin/javac 

I then re-downloaded a fresh copy the installer and ran it.

> java -version java version "1.8.0_05" > javac -version javac 1.7.0_21 

Update

I tried removing all JDK's, XCode and all developer tools, and re-installed fresh. Same results.

However, I'm still at a loss -- where do I go from here? How do I get javac 1.8 to get installed?

like image 898
Marty Pitt Avatar asked Apr 21 '14 17:04

Marty Pitt


People also ask

Is Java 8 and Java 1.8 are same?

In JDK 8 and JRE 8, the version strings are 1.8 and 1.8. 0. Here are some examples where the version string is used: java -version (among other information, returns java version "1.8.

How do I change Javac version?

If you want to run a different javac hit Windows + Pause and open the system dialog to change the PATH so it contains the path to your JDK 8 instead of your JDK 7. You will need to restart your command line for changes to show.

Is Java 1.7 the same as Java 7?

all the way to 1.7, also known as Java 7) usually contain improvements to both the JVM and the standard library, so the two usually need to run together, and are packaged together in the JRE. If you are running any Java program on your computer, you have a JRE installed. The JDK is the Java Development Kit.

Can I have both Java 7 and 8 installed?

You can install any number of JDK instances on your computer (and use them in projects or tools), but only one can be used as the main with JAVA_HOME env variable and its bin dir should be added to the PATH value like %JAVA_HOME%\bin .


1 Answers

If /usr/libexec/java_home -v 1.8.0_05 --exec javac -version returns the correct version, then your problem is with:

/System/Library/Frameworks/JavaVM.framework/Versions/CurrentJDK 

With a privileged user execute:

cd /System/Library/Frameworks/JavaVM.framework/Versions/ rm CurrentJDK ln -s /Library/Java/JavaVirtualMachines/jdk1.8.0_05.jdk/Contents/ CurrentJDK 

Solution found in Mankeh Blog


Also check this answer on Super User for dynamically switching JDK versions.


Update: I guess I've found the culprit!

Try this:

rm -rf ~/Library/Java/Extensions sudo rm -rf /Library/Java/Extensions 

Solution found in: Java 1.7 on OSX 10.9.2 running as 1.5?

like image 67
Anthony Accioly Avatar answered Sep 27 '22 21:09

Anthony Accioly