To make a Java version not accessible system wide in macOS i.e. to make it only invocable from the terminal:
- Go to
/Library/Java/JavaVirtualMachines
and then inside specific JDK directory - Inside
/Contents
renameInfo.plist
toInfo.plist.disabled
- Restart the system
This is useful if you want to run an application in macOS that needs for e.g. Java 8 but you have a later version installed (Java 15) which is the system default. Above workaround helps to override the system default Java version in macOS. Personally, this technique helped me to run Mulesoft Anypoint Platform which needs Java 8 even though I had higher version of Java installed in my system.