163

I just installed the latest Java SDK 7-67 from Oracle on the Mac 10.9.4. I then ran the command java -v in Terminal and I get this message:

Error: Could not create the Java Virtual Machine.
Error: A fatal exception has occurred. Program will exit.

1
  • Which version of Java did you download and Install, 32 bit or 64 bit?
    – Raf
    Sep 1, 2014 at 16:00

7 Answers 7

385

Normally this error occurs when you invoke java by supplying the wrong arguments/options. In this case it should be the version option.

java -version

So to double check you can always do java -help, and see if the option exists. In this case, there is no option such as v.

10
  • 25
    if it is a command or (argument) problem, then it should issue a different error! Not "Could not create the Java Virtual Machine".
    – Raf
    Sep 1, 2014 at 16:01
  • 2
    If you see the log fully, you can see:Unrecognized option: -v Error: Could not create the Java Virtual Machine. Error: A fatal exception has occurred. Program will exit.
    – BatScream
    Sep 1, 2014 at 16:02
  • 3
    Thanks all - yes sorry I just spotted the first line in which it says its an invalid argument. Java -version works now. Its just I installed something called node.js and to check its version it just requires -v. I thought it may have been a generic argument. Sep 1, 2014 at 16:08
  • 9
    Thank you for this. I spent 15 minutes looking into different ways the VM could be failing to load because I was typing --version instead of -version. And yes, what an utterly garbage error message -_-;
    – Gavin
    Feb 27, 2018 at 15:58
  • 3
    "I just installed something called node.js". ~5 years later, this looks terribly cute. Feb 21, 2019 at 20:18
4

So try uninstalling all other versions other than the one you need, then set the JAVA_HOMEpath variable for that JDK remaining, and you're done.

That's worked for me, I have two JDK (version 8 & 11) installed on my local mac, that causes the issue, for uninstalling, I followed these two steps:

  • cd /Library/Java/JavaVirtualMachines
  • rm -rf openjdk-11.0.1.jdk
0
3

if you tried running java with -version argument, and even though the problem could not be solved by any means, then you might have installed many java versions, like JDK 1.8 and JDK 1.7 at the same time.

So try uninstalling all other versions other than the one you need, then set the JAVA_HOMEpath variable for that JDK remaining, and you're done.

1
  • Yes its becoz of multiple version install, but how can I uninstall other version, Can you please help on this? Jul 31, 2018 at 18:32
1

Unrecognized option: - Error: Could not create the Java Virtual Machine. Error: A fatal exception has occurred. Program will exit.

I was getting this Error due to incorrect syntax using in the terminal. I was using java - version. But its actually is java -version. there is no space between - and version. you can also cross check by using java -help.

i hope this will help.

1

I faced this issue ,when i tried to launch uiautomatorviewer.I had java 13 version . Later i downloaded the java 8 version . Go to terminal and open .bash_profile. Enter export JAVA_HOME=$(/usr/libexec/java_home -v 1.8). Save and Exit .

2
  • 1
    I think the issue here was that the command was wrong. Changing the version of java might not be the best solution. Instead please use the right command for the version of java. Jul 7, 2021 at 14:22
  • 1
    The command was right ,i tried all finally i tried this it worked . Mac you dont need to downgrade the java version ,Instead adding the java home java 8 version worked.
    – abaranji
    Jul 8, 2021 at 15:04
0

There can be one more reason for such behavior - you delete current working directory.

For example:

# in terminal #1
cd /home/user/myJavaApp

# in terminal #2
rm -rf /home/user/myJavaApp

# in terminal #1
java -jar myJar.jar

Error: Could not create the Java Virtual Machine.
Error: A fatal exception has occurred. Program will exit.
0

Try : java -version , then if you see java 11

try to delete with terminal : cd /Library/Java/JavaVirtualMachines rm -rf openjdk-11.0.1.jdk

if it doesn't try delete manually: 1) click on finder 2) go to folder 3) post /Library/Java/JavaVirtualMachines 4) delete java 11 .

then try java version and you will see : java version "1.8.0_191"

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.