How can you change the default version of Java on a mac?
An easy way to include a separately installed JDK in the list given by /usr/libexec/java_home -V
is to symlink the directory as follows:
sudo ln -s path/to/jdk /Library/Java/JavaVirtualMachines/jdk-[some-identifier].jdk
For example, to register the JDK included with Android Studio (1.8.0_152 at the time of writing), use:
sudo ln -s /Applications/Android\ Studio.app/Contents/jre/jdk /Library/Java/JavaVirtualMachines/jdk-android-studio.jdk
Now java_home
will list the JDK under Matching Java Virtual Machines
and you can select it as described above.