This topic describes how to deploy an Open Java Development Kit (OpenJDK) environment in different operating systems, including checking whether a Java environment is installed, uninstalling the existing Java environment, and installing an OpenJDK environment of a specific Java version.
Install OpenJDK
You must connect to the Elastic Compute Service (ECS) on which you want to install OpenJDK. For more information, see Use Workbench to connect to a Linux instance over SSH.
Linux
Run the java -version command to check whether a Java environment is installed. If Java version information is returned, a Java environment is installed. If the current Java environment does not meet your business requirements, perform the following steps to uninstall the environment.
Update the package manager.
Run the following command in operating systems that use the Dandified YUM (DNF) tool, such as Alibaba Cloud Linux 3 and CentOS 8:
sudo dnf updateRun the following command in operating systems that use the Yellowdog Updater Modified (YUM) tool, such as Alibaba Cloud Linux 2 and CentOS 7:
sudo yum updateRun the following command in operating systems that use the Advanced Packaging Tool (APT) tool, such as Ubuntu and Debian:
sudo apt update
Search for OpenJDK to view the installation packages supported by the current operating system.
Run the following command in operating systems that use the DNF tool, such as Alibaba Cloud Linux 3 and CentOS 8:
sudo dnf search openjdkRun the following command in operating systems that use the YUM tool, such as Alibaba Cloud Linux 2 and CentOS 7:
sudo yum search openjdkRun the following command in operating systems that use the APT tool, such as Ubuntu and Debian:
sudo apt search openjdk
Install an OpenJDK environment of a specific Java version. In the following commands, the OpenJDK environment of Java version 1.8 is used. If you want to use another Java version, replace the package names in the commands with the package names that you queried in the preceding step.
Run the following command in operating systems that use the DNF tool, such as Alibaba Cloud Linux 3 and CentOS 8:
sudo dnf install -y java-1.8.0-openjdk-develRun the following command in operating systems that use the YUM tool, such as Alibaba Cloud Linux 2 and CentOS 7:
sudo yum install -y java-1.8.0-openjdk-develRun the following command in operating systems that use the APT tool, such as Ubuntu and Debian:
sudo apt-get install -y openjdk-8-jdk
Run the following command to check whether the OpenJDK environment of the Java version is installed as expected and whether the version information is displayed.
NoteBy default, symbolic links are configured when you install the OpenJDK environment of the Java version by using a package manager. You do not need to configure environment variables.
java -version
Windows
In the following example, the OpenJDK environment of Java version 1.8 is used. To download the OpenJDK installation package from the official website, your Windows instance must have access to the Internet.
Download the installation package
Go to the OpenJDK 8 official website and download the OpenJDK 8 installation package.
If you want to install another version, select Java SE <xx> in the left-side navigation pane of the official website. Replace <xx> with the version that you want to install. For example, if you want to download OpenJDK 21, select Java SE 21 in the left-side navigation pane.

Install OpenJDK
In the following example, the C:/Program Files directory is used. To install OpenJDK in another directory, replace the C:/Program Files directory with the directory that you want to use.
Go to the
Program Filesfolder on disk C and find the Java installation package that you downloaded.
Decompress the Java installation package, go to the decompressed directory, and then obtain the absolute path in the address bar.

Configure environment variable settings.
Right-click This PC and select Properties.

On the About page, scroll down to and click Advanced system settings.

Click Environment Variables.

In the System variables section, click New. In the New System Variable dialog box, set the Variable name parameter to
JAVA_HOMEand the Variable value parameter to the absolute path that you obtained in the address bar after the Java package was decompressed. Then, click OK to save the system variable.
Find and select the Path variable in the System variables section and click Edit.

Create two paths.
%JAVA_HOME%\bin %JAVA_HOME%\jre\bin
Click OK twice to save the environment variable.

Press
Win+Rto open the Run dialog box and entercmdto open the Command Prompt window. Run the following command to check whether the OpenJDK environment of the Java version is installed as expected and whether the version information is displayed:java -version