Selasa, 02 September 2025

How to Install Multiple java on old linux ditribution

How to Install Multiple java on old linux ditribution Sometimes we need to install several versions of Java on Linux which are quite old
Managing multiple Java versions on old Linux can be achieved using various methods, including manual installation and configuration with update-alternatives

Installation and Configuration:

Download and Extract:
Download the desired JDK/JRE binary from Oracle's website. Extract the archive to a specific directory (e.g., /opt/java/jdk17.0_version). Repeat for each Java version you want to install.

Set JAVA_HOME:
For a specific application or user, you can set the JAVA_HOME environment variable to point to the desired Java installation directory. This is typically done in the user's .bashrc or .profile file.

# export JAVA_HOME=/opt/java/jdk17.0_version
# export PATH=$JAVA_HOME/bin:$PATH
## Repeat for other Java executables like 'jar', 'javadoc', etc.

Update System-Wide Alternatives:
To make a specific Java version the default for all users, use the update-alternatives command.

# update-alternatives --install "/usr/bin/java" "java" "/opt/java/jdk17.0_version/bin/java" 1
# update-alternatives --install "/usr/bin/jar" "jar" "/opt/java/jdk17.0_version/bin/jar" 1
# update-alternatives --install "/usr/bin/javac" "javac" "/opt/java/jdk17.0_version/bin/javac" 1
# # Repeat for other Java executables like 'jar', 'javadoc', etc.

The last argument 1 is the priority, which determines the default if multiple alternatives exist. Higher priority takes precedence.

Switching Versions:
To switch the default Java version system-wide, use:

# update-alternatives --config java

This will present a list of available Java installations, allowing you to choose the desired default by entering its corresponding number.

Important Notes:
  • Be mindful of the licensing terms for Oracle JDK, as older versions might have different licensing models. OpenJDK is a free and open-source alternative.
  • When using update-alternatives, ensure you add all relevant Java executables (e.g., java, javac, jar) to avoid inconsistencies.
  • Test your Java applications after changing the default Java version to ensure compatibility.