Last Updated: October 04, 2020
·
833
· junior-ales

How to check (and change) your default JDK with one command

To begin with, this tip is to Java developers using Mac OS (if you use linux check this tip).

If every time you need information about your installed JDKs, you feel hammered by environment variables, exports, bash_profiles and all those things, hell yeah this tip will be a relief to your head.

There's an utilitarian called java_home on OSX located at /usr/libexec that summarizes all your machine Java Preferences. How it works? Look at that:

  • You want to know your default JDK:

Picture

  • You want to know where is installed your JDK6:

Picture

  • You want to know where is installed your JDK7:

Picture

  • You want the list of installed JDK:

Picture

If you run the javahome command with an argument of a non-installed JDK (e.g. I don't have a JDK8 installed but I run `/usr/libexec/javahome -v 1.8`) the outcome will be the path of your default JDK.

Having that in mind, changing the current JDK becomes easy as follow:

Picture

Picture

Have fun!


source: http://blog.hgomez.net/blog/2012/07/20/understanding-java-from-command-line-on-osx/

Related protips:

How To Check If JDK Is 32-bit or 64-bit?