Install, upgrade, or replace OpenJDK on Linux and Windows ECS instances, including environment checks and version-specific setup.
Install OpenJDK
Connect to the ECS instance on which you want to install OpenJDK.
Linux
Run java -version to check for an existing Java installation. If the installed version does not meet your requirements, uninstall it first.
-
Update the package manager.
-
DNF-based systems (Alibaba Cloud Linux 3, CentOS 8):
sudo dnf update -
YUM-based systems (Alibaba Cloud Linux 2, CentOS 7):
sudo yum update -
APT-based systems (Ubuntu, Debian):
sudo apt update
-
-
Search for available OpenJDK packages.
-
DNF-based systems (Alibaba Cloud Linux 3, CentOS 8):
sudo dnf search openjdk -
YUM-based systems (Alibaba Cloud Linux 2, CentOS 7):
sudo yum search openjdk -
APT-based systems (Ubuntu, Debian):
sudo apt search openjdk
-
-
Install OpenJDK. The following example uses Java 1.8. To install a different version, replace the package name with the one from the previous step.
-
DNF-based systems (Alibaba Cloud Linux 3, CentOS 8):
sudo dnf install -y java-1.8.0-openjdk-devel -
YUM-based systems (Alibaba Cloud Linux 2, CentOS 7):
sudo yum install -y java-1.8.0-openjdk-devel -
APT-based systems (Ubuntu, Debian):
sudo apt-get install -y openjdk-8-jdk
-
-
Verify the installation.
NotePackage manager installations automatically configure symbolic links, so no manual environment variable setup is needed.
java -versionIf the installation is successful, output similar to the following is returned:
[root@iZbp1jxxx java]# java -version openjdk version "1.8.0_432" OpenJDK Runtime Environment (build 1.8.0_432-b06) OpenJDK 64-Bit Server VM (build 25.432-b06, mixed mode)
Windows
The following example uses Java 1.8. Your Windows instance must have Internet access to download the package.
Download the OpenJDK package
Download the package from the OpenJDK 8 official website.
To install a different version, select Java SE <xx> in the left-side navigation pane. Replace <xx> with the target version. For example, select Java SE 21 to download OpenJDK 21.
In the RI Binaries section of the download page, click the Windows 11 i586 Java Development Kit link to download.
Install OpenJDK
The following example uses C:/Program Files. Replace it with your preferred directory if needed.
-
Place the downloaded OpenJDK package (e.g.,
openjdk-8u44-windows-i586.zip) in theC:\Program Filesdirectory. -
Extract the package, open the extracted directory, and copy the absolute path from the address bar. The extracted OpenJDK directory path is
C:\Program Files\openjdk-8u44-windows-i586\java-se-8u44-ri, containing folders such as bin, jre, and lib. Confirm this path as the JAVA_HOME variable value for subsequent steps. -
Configure environment variables.
-
Right-click This PC and select Properties.
-
On the About page, scroll down and click Advanced system settings.
-
Click Environment Variables.
-
In System variables, click New. Set Variable name to
JAVA_HOMEand Variable value to the OpenJDK installation path (e.g.,C:\Program Files\openjdk-8u44-windows-i586\java-se-8u44-ri). Click OK. -
Select the Path variable in System variables and click Edit.
-
Add these two paths:
%JAVA_HOME%\bin %JAVA_HOME%\jre\bin -
Click OK twice to save the settings.
-
-
Press
Win+R, entercmd, and verify the installation:java -versionIf the installation is successful, output similar to the following is returned:
C:\Users\Administrator>java -version openjdk version "1.8.0_44" OpenJDK Runtime Environment (build 1.8.0_44-b02) OpenJDK Client VM (build 25.40-b25, mixed mode)