Search code examples
javajava-8javac

'java' command is working but 'javac' don't


I have set path variables.

Variable: JAVA_HOME
Value: C:\Program Files\Java\jdk1.8.0_101
Path: C:\ProgramData\Oracle\Java\javapath;

When I execute command 'java -version', output is

java version "1.8.0_102"
Java(TM) SE Runtime Environment (build 1.8.0_102-b14)
Java HotSpot(TM) 64-Bit Server VM (build 25.102-b14, mixed mode)

But when I type 'javac -version', output is

'javac' is not recognized as an internal or external command,
operable program or batch file.

Why javac ic not recognised?

PS: I have restarted my pc several times.


Solution

  • It looks like you have installed both a separate JRE and a JDK, of different versions, and your path includes only the bin directory of the JRE. You've shown JAVA_HOME as including version 1.8.0_101, but the -version output you're seeing says 1.8.0_102, so clearly isn't from that installation.

    I suggest finding and uninstalling the 1.8.0_101 JRE, then updating your PATH to include the two bin directories in the JDK installation. One of them will be basepath\jdk\bin, the other will be basepath\jdk\jre\bin. Include them in that order (JDK first). Then make sure JAVA_HOME points to that installation.


    Having just installed JDK 1.8.0_101 on a Windows machine I had handy, I can confirm that it adds the JRE bin directory to the path but not the JDK bin directory. If you want the JDK bin directory in the path as well, add C:\Program Files\Java\jdk1.8.0_101\bin to the PATH via the control panel (changing the version number if necessary).