IBM Support

Changing Default Version for JDK (java.version)

Troubleshooting


Problem

This document describes how to switch to a different JDK when you have multiple JDKs installed to your IBM i OS.

Resolving The Problem

Setting the job (*JOB) and default (*SYS) JDK version for the IBM Technology for Java VM on IBM i OS

 You can control the IBM Technology for Java VM version by setting the JAVA_HOME environment variable at the *JOB or *SYS level.
Note: Before setting the JAVA_HOME environment variable, ensure the JDK version and bit level's corresponding 57xxJV1 LPP Option has been installed.  See How to determine what Java Development Kits (JDKs) are installed and use them in your environment? for more information.

There are three common techniques for setting JAVA_HOME:
1.
Use the ADDENVVAR CL command.
For example, to add the variable to your current interactive job, enter the following on a CL command line:
ADDENVVAR ENVVAR(JAVA_HOME) VALUE('/QOpenSys/QIBM/ProdData/JavaVM/jdkXX/YYbit’) LEVEL(*JOB)
Where...
XX = 70, 71, 80, 11, 17, or 21
YY = 32 or 64

Java 17 64 bit example:
ADDENVVAR ENVVAR(JAVA_HOME) VALUE('/QOpenSys/QIBM/ProdData/JavaVM/jdk17/64bit’) LEVEL(*JOB)
====================================
Use the following if you want to set the environment variable at the system level and change the default Java version used by the IBM i OS.
ADDENVVAR ENVVAR(JAVA_HOME) VALUE('/QOpenSys/QIBM/ProdData/JavaVM/jdkXX/YYbit’) LEVEL(*SYS)
Where...
XX = 70, 71, 80, 11, 17, or 21
YY = 32 or 64
Java 8 64 bit Example:
ADDENVVAR ENVVAR(JAVA_HOME) VALUE('/QOpenSys/QIBM/ProdData/JavaVM/jdk80/64bit’) LEVEL(*SYS)

If you want to remove the JAVA_HOME variable type, use the following commands.
RMVENVVAR ENVVAR(JAVA_HOME) LEVEL(*JOB) - For Interactive job
RMVENVVAR ENVVAR(JAVA_HOME) LEVEL(*SYS) - System wide removal
2.
Set JAVA_HOME from within QSHELL.
a. Open a Qshell session using the STRQSH command.
b. Export the variable to your process:
export -s JAVA_HOME=/QOpenSys/QIBM/ProdData/JavaVM/jdkXX/YYbit
Where...
XX = 70, 71, 80, 11, 17, or 21
YY = 32 or 64

To remove the JAVA_HOME environment variable from within Qshell, use the unset command. For example, use the following:
unset JAVA_HOME
Example to switch the Qshell session to use JDK 17 64 bit:
export -s JAVA_HOME=/QOpenSys/QIBM/ProdData/JavaVM/jdk17/64bit
3.
Use a .profile file to initialize the shell.
If you would like JAVA_HOME to be set every time you start Qshell, you may create a .profile file in a user’s home directory. For example, if your i5/OS user profile is John, you would perform the following steps:
a. Create a file called .profile in /home/John.
b. Add the following text to the file:
export -s JAVA_HOME=/QOpenSys/QIBM/ProdData/JavaVM/jdkXX/YYbit
Where...
XX = 70, 71, 80, 11, 17, or 21
YY = 32 or 64

c. Save the file.
Note: You should not use the java.home or java.version system property to set the JDK home/version. This will not work on IBM i. In fact, if you attempt to set java.home in the SystemDefault.properties file, the Java product may stop working completely. The only way to change the JDK version and bit level is to set JAVA_HOME as an environment variable.
See the IBM i 7.6 Documentation for more information:

Supported IBM Java Development Kit (JDK) Versions by IBM i Operating System Version and Release

[{"Type":"MASTER","Line of Business":{"code":"LOB68","label":"Power HW"},"Business Unit":{"code":"BU070","label":"IBM Infrastructure"},"Product":{"code":"SWG60","label":"IBM i"},"ARM Category":[{"code":"a8m0z0000000CH5AAM","label":"Java Development Kit"}],"ARM Case Number":"","Platform":[{"code":"PF012","label":"IBM i"}],"Version":"All Versions"}]

Historical Number

19754920

Document Information

Modified date:
02 May 2025

UID

nas8N1017748