Search code examples
javaionic-frameworkjavac

Failed to run "javac -version" make sure that you have a JDK version 8 installed


I am new to ionic and I have tried everything available on the internet regarding this issue but i haven`t found any suitable/matching solution.

Details of my problem :

I am working with ionic 5 and when I am running ionic cordova run android then after a while I have got the following error :

Failed to run "javac -version", make sure that you have a JDK version 8 installed.
You can get it from the following location:
https://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html

Your JAVA_HOME is invalid: /usr/lib/jvm/java-8-openjdk-amd64
[ERROR] An error occurred while running subprocess cordova.
    
    cordova build android --device exited with exit code 1.
    
    Re-running this command with the --verbose flag may provide more information.

I have already installed java, cordova and android studio on my PC(ubuntu 16.04) following are some details :

command : java -version

result :

openjdk version "1.8.0_252"
OpenJDK Runtime Environment (build 1.8.0_252-8u252-b09-1~16.04-b09)
OpenJDK 64-Bit Server VM (build 25.252-b09, mixed mode)

command : javac -version result :

The program 'javac' can be found in the following packages:
 * default-jdk
 * ecj
 * gcj-5-jdk
 * openjdk-8-jdk-headless
 * gcj-4.8-jdk
 * gcj-4.9-jdk
 * openjdk-9-jdk-headless
Try: sudo apt install <selected package>

Solution

  • apt-install default-jdk, which is basically what that last message is telling you to do, should do the trick.

    Debian/Ubuntu have different packages for the JRE and the JDK. You installed the JRE only.