37

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?

Community
  • 1
  • 1
Marty Pitt
  • 28,822
  • 36
  • 122
  • 195
  • not sure this can help but try uninstalling everything related to JDK/JRE and try fresh install of JDK/JRE refer http://askubuntu.com/questions/84483/how-to-completely-uninstall-java – dev2d Apr 26 '14 at 00:16
  • Can you try `/usr/libexec/java_home -v 1.8.0_05 --exec javac -version`? – Anthony Accioly Apr 26 '14 at 00:25
  • @AnthonyAccioly Ran your command verbatim: `javac 1.7.0_21` – Marty Pitt Apr 26 '14 at 00:38
  • @VD' : I tried that, removing all JDK's from my machine. Are there other steps I should take? – Marty Pitt Apr 26 '14 at 00:39
  • Just to be sure, can you remove jdk 1.8 and try again? If it still finds javac 1.7.0 there is something funky with your PATH, else it may be a situation like the one @skiwi suggested (which unfortunately I can't reproduce). – Anthony Accioly Apr 26 '14 at 00:43
  • @AnthonyAccioly Nuked, and re-installed, problem persists. (See updates) – Marty Pitt Apr 26 '14 at 01:16
  • So bizarre. Maybe the JDK is reporting the wrong version? Can you try to compile Java 8 specific code (such as one of the [Lambda Examples](http://www.oracle.com/webfolder/technetwork/tutorials/obe/java/Lambda-QuickStart/index.html#section2))? – Anthony Accioly Apr 26 '14 at 03:19
  • I have just installed JDK 1.8u5 on my OS X box (10.9.2), and it worked fine. My `/Library/Java/JavaVirtualMachines` contains only jdk1.8.0_05. – nneonneo Apr 26 '14 at 03:45
  • Can you try `env -i javac -version` and see what you get? – nneonneo Apr 26 '14 at 03:46
  • Poking around: Can you try this: `sudo dtruss -f javac 2> javac.dtruss-f.txt` ? Then take a look, which files are accessed and whether you see weird paths showing up. – Rainer Schwarze Apr 26 '14 at 06:16
  • @RainerSchwarze Sure: https://gist.github.com/martypitt/11316117. Perhaps you could do the same, and diff? – Marty Pitt Apr 26 '14 at 09:55
  • @nneonneo: `javac 1.7.0_21` – Marty Pitt Apr 26 '14 at 09:55
  • @MartyPitt -I saw, that the issue is solved "already" :-) Anyway - your log looks as good as mine and it would not have given a hint to the solution - best wishes... – Rainer Schwarze Apr 26 '14 at 20:12
  • Hi @Rainer, the problem was a sneaky old `tools.jar` loaded by javac. An anonymous good soul was [able to spot it](http://stackoverflow.com/questions/22519596/java-compilation-error-mac) with DTrace (gotta love it :)). – Anthony Accioly Apr 27 '14 at 22:59
  • @AnthonyAccioly I am not familiar with DTrace/dtruss, but from what I quickly saw about dtruss, I would have expected, that the -f option should have dug to that place. My next guess would be to look at the java launching framework files which were seen in the log, but as the problem was already solved ... :-) (DTrace etc.: coming from DOS/Windows lots of years ago, I am frequently amazed how nice things are in the unix world.) – Rainer Schwarze Apr 29 '14 at 10:44
  • I'm having the same exact issue and am not really clear on how this got resolved. To me it looks like the 1.7 version of javac came bundled with jdk 1.8. – Scott Turley Jun 29 '16 at 19:42

6 Answers6

39

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?

Anthony Accioly
  • 21,918
  • 9
  • 70
  • 118
  • Thanks Anthony. Unforutnately: `/usr/libexec/java_home -v 1.8.0_05 --exec javac -version` returns `javac 1.7.0_21` – Marty Pitt Apr 26 '14 at 00:41
  • 1
    Glad 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! – Anthony Accioly Apr 26 '14 at 14:42
  • Thanks Brazilian, worked for me, too bad brazil lost 1-7 in world cup..I am a big fan of Brazilian soccer. – TharakaNirmana Jul 10 '14 at 05:20
  • Work for me this solution! rm -rf ~/Library/Java/Extensions sudo rm -rf /Library/Java/Extensions Thanks!!!! – VictorV Nov 30 '14 at 02:33
  • `~/Library/Java/Extensions /Library/Java/Extensions` – sAguinaga Feb 01 '15 at 12:11
  • Anthony, you rock! Deleting /Library/Java/Extensions worked! Thanks! – stuff22 Apr 07 '15 at 16:10
  • @AnthonyAccioly thank you very very very much! I was minutes away from removing jenv from my machine thinking that it has messed everything up... – Filip Jul 02 '15 at 15:19
  • @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? – psun Mar 26 '16 at 16:43
  • @psun, are you linking to the correct JDK folder? (Folder location may change according to the Java Version) – Anthony Accioly Mar 26 '16 at 19:13
  • my command was `ln -s /Library/Java/JavaVirtualMachines/jdk1.8.0_77.jdk/Contents/ Current`. – psun Mar 26 '16 at 20:41
  • And 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 the `PATH` (maybe you should `echo $PATH` and figure out where OS X is expecting to find the Java command and where it actually is) – Anthony Accioly Mar 26 '16 at 22:03
  • Downloading and installing the Mac OS JDK worked for me: http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html – CoderDave Dec 27 '16 at 05:20
9

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.

KayG
  • 103
  • 1
  • 6
0

This is (most likely) a bug in the installation process of jre8.

I am getting the exact same behaviour when navigating to my jre8 folder, which is the one which Windows (in my case) shows by default:

  • java version: 1.8.0, runtime environment 1.8.0-b132, hotspot 64-bit JVM 25.0-b70
  • javac version: 1.7.0_25

When navigating to the jdk8 directory, it shows the following:

  • java version: 1.8.0, runtime environment 1.8.0-b132, hotspot 64-bit JVM 25.0-b70
  • javac version: 1.8.0

I did just now notice though that the jre does never ship an javac, so this is an issue in the reference settings in the operating system then I guess.

To fix it, you would need to manually fix the javac reference in your OS.

skiwi
  • 66,971
  • 31
  • 131
  • 216
  • Thanks -- 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 that `javac` wasn't within the JRE folder, as it's part of the JDK, not JRE. – Marty Pitt Apr 21 '14 at 21:20
  • Further 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 that `javac` that's being executed is the one that's within the `jdk8` 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 Apr 26 '14 at 00:12
0

Maybe you can delete the standard .jar file which in your classpath. When i delete the jar in /Library/Java/Extensions, the problem will be solved. More info : Java compilation error: Mac

Community
  • 1
  • 1
  • This is included in [After upgrading to Java8, javac still shows 1.7](//stackoverflow.com/a/23305195) – Danh Jan 01 '17 at 14:49
0

Just adding my own experience here, I installed jdk-8u131-macosx-x64 from Oracle. Everything worked perfectly. No JAVA_HOME environment variables were present or needed.

mehboob$ javac -version
javac 1.8.0_131

mehboob$ java -version
java version "1.8.0_131"
Java(TM) SE Runtime Environment (build 1.8.0_131-b11)
Java HotSpot(TM) 64-Bit Server VM (build 25.131-b11, mixed mode)

The /System/Library showed this:

mehboob$ ls -l /System/Library/Frameworks/JavaVM.framework/Versions/
total 64
lrwxr-xr-x  1 root  wheel   10 Oct 17  2013 1.4 -> CurrentJDK
lrwxr-xr-x  1 root  wheel   10 Oct 17  2013 1.4.2 -> CurrentJDK
lrwxr-xr-x  1 root  wheel   10 Oct 17  2013 1.5 -> CurrentJDK
lrwxr-xr-x  1 root  wheel   10 Oct 17  2013 1.5.0 -> CurrentJDK
lrwxr-xr-x  1 root  wheel   10 Oct 17  2013 1.6 -> CurrentJDK
lrwxr-xr-x  1 root  wheel   10 Oct 17  2013 1.6.0 -> CurrentJDK
drwxr-xr-x  8 root  wheel  272 Sep  9  2014 A
lrwxr-xr-x  1 root  wheel    1 Oct 17  2013 Current -> A
lrwxr-xr-x  1 root  wheel   59 Oct 17  2013 CurrentJDK -> /System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents

While the /Library/Java had this:

mehboob$ ls -l /Library/Java/
total 8
drwxrwxr-x  2 root  admin   68 Oct 17  2013 Extensions
lrwxr-xr-x  1 root  wheel   48 Oct 17  2013 Home -> /System/Library/Frameworks/JavaVM.framework/Home
drwxr-xr-x  3 root  wheel  102 Jun  9 11:43 JavaVirtualMachines

There was nothing in Extensions, while JavaVirtualMachines only had the jdk1.8.0_131.jdk folder.

This shows that a default installation of JDK works properly with no extra configuration required.

machinat
  • 41
  • 4
0

Firstly, you need to download and then install the jdk8(http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html)

Secondly, do some check as follows: Does your system have a not-linked-for-shell use java 8 already? Try this in you terminal (yes, the apostrophes are important):

$ '/Library/Internet Plug-Ins/JavaAppletPlugin.plugin/Contents/Home/bin/java' -version 

if it shows " java version "1.8.0_131" " , and then you can go to next step.

my screenshot

Thirdly, edit the bash_profile:

$ vi ~/.bash_profile 

and type this:

JAVA_HOME="/Library/Internet Plug-Ins/JavaAppletPlugin.plugin/Contents/Home"
PATH=$JAVA_HOME/bin:$PATH
CLASSPATH=.:$JAVA_HOME/lib
export JAVA_HOME
export CLASSPATH 

save it and quit, then

source ~/.bash_profile 

After the above steps, and check the java version

$ java -version
java version "1.8.0_131"
Java(TM) SE Runtime Environment (build 1.8.0_131-b11)
Java HotSpot(TM) 64-Bit Server VM (build 25.131-b11, mixed mode)
Huang
  • 51
  • 4