Archive for the ‘Mac’ Category

Java on Mac Cheat sheet

Install AdoptOpenJDK following instructions for macOS. The instructions don’t say where to install it, I suggest /Library/Java/JavaVirtualMachines. This will get you the built-in mac behavior.

Built-in mac behavior

Older versions of Java created a Java button in System Preferences. It will not show Java 11, but it will show older versions. In my case, I had some old projects using Java 8.

The other built-in is the java_home utility.

List available versions

alias javas_avail='/usr/libexec/java_home -V'

Example output:

Matching Java Virtual Machines (2):
11.0.1, x86_64: "OpenJDK 11.0.1" /Library/Java/JavaVirtualMachines/jdk-11.0.1.jdk/Contents/Home
1.8.0_161, x86_64: "Java SE 8" /Library/Java/JavaVirtualMachines/jdk1.8.0_161.jdk/Contents/Home

Switch to a specific version

java_home will also allow you to switch to a given version. For example

$ export JAVA_HOME=`/usr/libexec/java_home -v 1.8`
$ java -version
java version "1.8.0_161"
Java(TM) SE Runtime Environment (build 1.8.0_161-b12)
Java HotSpot(TM) 64-Bit Server VM (build 25.161-b12, mixed mode)

If you find yourself switching versions a lot, create an alias for it.