JDK install & config

Introduction

TBD

Reference

Java Licensing Methodology

See sections "Which version of Oracle Java JDK requires a license ?" and "Was Oracle Java (JDK / JRE ) –  free before 2019?".
Also the FAQs "If we have Java 6 do we need a license?", "We have Java 7 do we need a license?" and "We have Java 8 with a security patch 91 do we need a license?"

https://redresscompliance.com/oracle-java-licensing-changes-explaned-free/


Java license

If using OpenJDK no license is needed.
If using Oracle Java then keep reading and review the reference "Java Licensing Methodology".


Oracle changed the licensing since Java 1.8 security patch 211:

The BCLA allowed for commercial usage if you were using Oracle Java for “general purpose computing”, otherwise a license is needed.
There is a licensing agreement restricting the free use to “office suite productivity tools and internet browsing”.

Java Enterprise (MSI) Installer

Java Flight Recorder 

Java Mission Control 

JRE Usage Tracking

Java Advanced Management Console

Jrockit Mission Control, Flight Recorder, or Real time Deterministic GC 


Java environment variables and system properties (including proxies)

See sub-page:

https://sites.google.com/site/pawneecity/java-development/jdk-install-config/java-environment-variables-and-system-properties-including-proxies

JDK install

OpenJDK 21

Tested in Ubuntu 22.04 & 23.04:

sudo apt update && sudo apt install openjdk-21-jdk

update-java-alternatives -l

sudo update-java-alternatives --set java-1.21.0-openjdk-amd64
      update-alternatives: error: no alternatives for jaotc

      It changes all other java alternatives: jaotc was removed in JDK 17


OpenJDK 17

Tested in Ubuntu 20.04 & 21.04:

sudo apt update && sudo apt install openjdk-17-jdk

sudo update-java-alternatives --set java-1.17.0-openjdk-amd64


OracleJDK 17

Tested in Ubuntu 22.04:

sudo add-apt-repository ppa:linuxuprising/java -y

sudo apt update

sudo apt install oracle-java17-installer


JDK 5

See subpage:

https://sites.google.com/site/pawneecity/java-development/jdk-install-config/java-5-jdk-install-config


Aid various client software in locating where Java is installed

We may aid various client software in locating where Java in installed, by adding a few environment variables. Do this by editing .bashrc in your home directory.

$ sudo gedit $HOME/.bashrc


Scroll down to the end of the file and add new lines:

#JDK 21

export JDK_HOME=/usr/lib/jvm/java-1.21.0-openjdk-amd64 && export JAVA_HOME=$JDK_HOME

#JDK 17

#export JDK_HOME=/usr/lib/jvm/java-1.17.0-openjdk-amd64 && export JAVA_HOME=$JDK_HOME

#JDK 11

#export JDK_HOME=/usr/lib/jvm/java-1.11.0-openjdk-amd64 && export JAVA_HOME=$JDK_HOME

#JDK 8

#export JDK_HOME=/usr/lib/jvm/java-8-oracle && export JAVA_HOME=$JDK_HOME


JDK switch (bash aliases)

Maven (and other programs relaying on environment variable JAVA_HOME)

A convenient way is adding some aliases, as follows.

$ gedit ~/.bash_aliases

# JDKs

alias jdk21='export JDK_HOME=/usr/lib/jvm/java-1.21.0-openjdk-amd64 && export JAVA_HOME=$JDK_HOME && $JAVA_HOME/bin/java -version'

alias jdk17='export JDK_HOME=/usr/lib/jvm/java-1.17.0-openjdk-amd64 && export JAVA_HOME=$JDK_HOME && $JAVA_HOME/bin/java -version'

alias jdk17oracle='export JDK_HOME=/usr/lib/jvm/java-17-oracle && export JAVA_HOME=$JDK_HOME && $JAVA_HOME/bin/java -version'

alias jdk11='export JDK_HOME=/usr/lib/jvm/java-1.11.0-openjdk-amd64 && export JAVA_HOME=$JDK_HOME && $JAVA_HOME/bin/java -version'

alias jdk8oracle='export JDK_HOME=/usr/lib/jvm/java-8-oracle && export JAVA_HOME=$JDK_HOME && $JAVA_HOME/bin/java -version'

alias jdk7='export JDK_HOME=/usr/lib/jvm/java-7-sun && export JAVA_HOME=$JDK_HOME && $JAVA_HOME/bin/java -version'

alias jdk5='export JDK_HOME=/usr/lib/jvm/java-5-sun && export JAVA_HOME=$JDK_HOME && $JAVA_HOME/bin/java -version'

$ source ~/.bash_aliases

Usage:

$ jdk21

openjdk version "21-ea" 2023-09-19

OpenJDK Runtime Environment (build 21-ea+14-Ubuntu-0ubuntu1)

OpenJDK 64-Bit Server VM (build 21-ea+14-Ubuntu-0ubuntu1, mixed mode, sharing)


$ jdk17

openjdk version "17.0.5" 2022-10-18

OpenJDK Runtime Environment (build 17.0.5+8-Ubuntu-2ubuntu122.04)

OpenJDK 64-Bit Server VM (build 17.0.5+8-Ubuntu-2ubuntu122.04, mixed mode, sharing)


$ jdk11

openjdk version "11.0.9.1" 2020-11-04

OpenJDK Runtime Environment (build 11.0.9.1+1-Ubuntu-0ubuntu1.20.04)

OpenJDK 64-Bit Server VM (build 11.0.9.1+1-Ubuntu-0ubuntu1.20.04, mixed mode, sharing)


$ jdk8

java version "1.8.0_212"

Java(TM) SE Runtime Environment (build 1.8.0_212-b10)

Java HotSpot(TM) 64-Bit Server VM (build 25.212-b10, mixed mode)


$ jdk7

java version "1.7.0_80"

Java(TM) SE Runtime Environment (build 1.7.0_80-b15)

Java HotSpot(TM) 64-Bit Server VM (build 24.80-b11, mixed mode)


$ jdk5

java version "1.5.0_22"

Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_22-b03)

Java HotSpot(TM) 64-Bit Server VM (build 1.5.0_22-b03, mixed mode)