Try the following steps:
Go to Finder-> Utilities-> Java and open "Java Settings" and select your preferred version.
- Open a terminal and go to /System/Library/Frameworks/JavaVM.framework/Versions/
- Type ls -l to display all available versions of Java.
- Type sudo ln -fhsv CurrentJDK
Link: Changing Java version on Mac
source share