After upgrading to Java8, javac still shows 1.7
Solution 1
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?
Solution 2
For Windows users:
It is possible, that you have to change your PATH variable. Try to set your "%JAVA_HOME%/bin" as the first entry in the PATH.
So now it looks like this:
PATH C:\Program Files\anyprogram;C:\Program Files\...;%JAVA_HOME%\bin
And you change it like this:
PATH %JAVA_HOME%\bin;C:\Program Files\anyprogram;C:\Program Files\...
Reason: Any other Program initiates an other Java Version first.
Marty Pitt
Updated on June 12, 2020Comments
-
Marty Pitt almost 4 years
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 toA
. The contents ofA/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?
-
Marty Pitt about 10 yearsThanks -- I suspect the root cause is the same (a javac somewhere). The folder structures in OSX and Windows are pretty different. OSX scatters it's JDK files, (and pointers to these files) all over the place, so as such, there is no
jdk8
directory. It makes sense thatjavac
wasn't within the JRE folder, as it's part of the JDK, not JRE. -
Marty Pitt about 10 yearsFurther to this, I've done more investigation on the paths that
javac
is resolving to. Based on the updated info in the question, I'm confident thatjavac
that's being executed is the one that's within thejdk8
paths. I'm not confident that it's the same as the one that ships with jdk8, but I'm not doing anything beyond running a vanilla install. Odd. -
Marty Pitt about 10 yearsThanks Anthony. Unforutnately:
/usr/libexec/java_home -v 1.8.0_05 --exec javac -version
returnsjavac 1.7.0_21
-
Anthony Accioly about 10 yearsGlad to be of service. The Alliterated pixelated version of me says "Thanks for yummy bounty". The real me says: "If you ever come to Brazil let's have a beer and talk about permanently dropping Java development in OS X!" I did when Apple started dropping the ball - before Oracle was able to pick it up of course - now I'm a very happy openSUSE user and I can't complain about a thing! Really! It just works!
-
TharakaNirmana almost 10 yearsThanks Brazilian, worked for me, too bad brazil lost 1-7 in world cup..I am a big fan of Brazilian soccer.
-
VictorV over 9 yearsWork for me this solution! rm -rf ~/Library/Java/Extensions sudo rm -rf /Library/Java/Extensions Thanks!!!!
-
sAguinaga over 9 years
~/Library/Java/Extensions /Library/Java/Extensions
-
stuff22 about 9 yearsAnthony, you rock! Deleting /Library/Java/Extensions worked! Thanks!
-
Filip almost 9 years@AnthonyAccioly thank you very very very much! I was minutes away from removing jenv from my machine thinking that it has messed everything up...
-
psun about 8 years@Anthony, I tried the solution from Mankeh blog, now my
java -version
command not working. it gives,-bash: java: command not found
error. how can I fix it? -
Anthony Accioly about 8 years@psun, are you linking to the correct JDK folder? (Folder location may change according to the Java Version)
-
psun about 8 yearsmy command was
ln -s /Library/Java/JavaVirtualMachines/jdk1.8.0_77.jdk/Contents/ Current
. -
Anthony Accioly about 8 yearsAnd is this a valid instalation with
java
,javac
set to the right permissions? From your error message looks like OS X can't find Java in thePATH
(maybe you shouldecho $PATH
and figure out where OS X is expecting to find the Java command and where it actually is) -
CoderDave over 7 yearsDownloading and installing the Mac OS JDK worked for me: oracle.com/technetwork/java/javase/downloads/…
-
Danh over 7 yearsThis is included in After upgrading to Java8, javac still shows 1.7