others-how to solve 'Unable to find any JVMs matching version' when openning a terminal window in MacOS?

1. Purpose

In this post, I would demo how to solve the below error when we openning a terminal window in MacOS

Unable to find any JVMs matching version "1.6".

2. Environment

  • Mac OS 10.15
  • Java 1.8

3. The solution

3.1 What does this error mean?

Check the local java installation by running the following command:

$ java --version
java version "1.8.0_121"
Java(TM) SE Runtime Environment (build 1.8.0_121-b13)
Java HotSpot(TM) 64-Bit Server VM (build 25.121-b13, mixed mode)

This error indicates that there should be a java 1.6 in my system, but it does not.

3.2 Solution #1

Install the specified java version for your system(Just choose from one of the following commands)

brew tap caskroom/versions
brew cask install java6 # for jdk6
brew cask install java7 # for jdk7
brew cask install java8 # for jdk8

3.3 Solution #2

If you don’t want to install the specified java version in your system, you can just remove all the references of it from such files:

~/.bash_profile
~/.zshrc
/etc/profile

In my case, I removed the following references as follows:

#export JAVA_6_HOME=$(/usr/libexec/java_home -v1.6)
#alias java6='export JAVA_HOME=$JAVA_6_HOME'

And then restart the terminal, the warning message disappears.

Last login: Fri May  7 17:24:20 on ttys002
You have mail.
➜  ~

Now it works!

4. Summary

In this post, I demonstrated how to solve ‘Unable to find any JVMs matching version’ error when openning a terminal window in MacOS.