Thursday, July 12, 2018

How to install or update your preferred JDK with one single command on macOS or GNU/Linux?

What is your preferred JRE/JDK? Is it the Oracle JDK from oracle.com or the JRE from java.com, the OpenJDK from jdk.java.net or the OpenJDK from adoptopenjdk.net? Whatever your preference is, you can install or update the JDK with only one single command on macOS or GNU/Linux with the bash script called update_jre.

You can download it from here for free:
https://github.com/jonelo/bash-dwarfs/blob/master/bin/update_jre

And here comes the one-liner:

sudo ./update_jre -az -s adoptopenjdk.net -t openjdk10 /opt/java/jdk/
The command above downloads the OpenJDK 10 from adoptopenjdk.net (you can specify the source and type with -s and -t), extracts it, applies the latest time zone data from IANA by downloading, extracting and calling the latest time zone updater (you have to accept the Oracle license by specifying the -a option) and it saves .version files that store the URI of the actual download for re-run purposes (see below). In /opt/java/jdk/ you will then find symlinks that point to the latest latest updated OpenJDK 10 folder (and the latest tzupdater.jar if you run the script with -z). Now you have a fixed path that you can use to configure your IDE, apps, whatever.
$ /opt/java/jdk/openjdk10_latest/bin/java -version
openjdk version "10.0.1-adoptopenjdk" 2018-04-17
OpenJDK Runtime Environment (build 10.0.1-adoptopenjdk+10)
OpenJDK 64-Bit Server VM (build 10.0.1-adoptopenjdk+10, mixed mode)
If you re-run the script above, it will only download the bits if they are different from those that you have downloaded already (it simply compares the .version file), updates the JDK that you have specified with -t and recreates the symlinks. So with the update_jre script you stay up to date the easy way.

BTW, I started the update_jre script with downloading the JRE and therefore the script is called update_jre and not update_jdk.
 

No comments:

Post a Comment