Updated on 2024-07-19 GMT+08:00

Installing JDK

This section describes how to install JDK on the Windows and Linux OSs and verify that the installation is successful.

Installing JDK in Windows

  1. Download the JDK file from the official website. JDK 8 is used as an example. Click DOWNLOAD below JDK.

  2. After the JDK file is downloaded, install the JDK as prompted. For example, install the JDK to the C:\Program Files\Java\jdk1.8.0_131 directory on the local PC.
  3. Configure Java environment variables.

    1. Right-click Computer, choose Properties > Advanced system settings.
    2. Click the Advanced tab, and then click Environment Variables.
    3. Set JAVA_HOME, PATH, and CLASSPATH (case-insensitive) in the System variables area. See Table 1.

      If the three variables already exist, click Edit. If not, click New.

      Table 1 JAVA environment variables

      Variable

      Value

      Description

      JAVA_HOME

      JDK installation path

      Example: C:\Program Files (x86)\Java\jdk1.8.0_1311

      PATH

      %JAVA_HOME%\bin;%JAVA_HOME%\jre\bin

      Add it to the end of the original PATH value.

      CLASSPATH

      .;%JAVA_HOME%\lib\dt.jar;%JAVA_HOME%\lib\tools.jar;

      There is a dot (.) in front of the value.

  4. Open the CLI and run java -version. The Java environment variables have been configured if the Java version is displayed.

    The following is a successful response example:

Installing JDK in Linux

  1. Download the JDK installation package based on system requirements. You are advised to download JDK1.8.

    Select Accept License Agreement before downloading the package.

    Figure 1 Downloading the JDK

  2. Run the following command to decompress the installation package to the JDK directory:

    tar -xvf jdk-8u191-linux-x64.tar.gz -C /home/vod/jdk/

  3. Set environment variables.

    1. Run the vi /etc/profile command to open the profile file.
    2. Add the following content to the end of the file:
      #set java environment
      export JAVA_HOME=/home/vod/jdk/jdk1.8.0_191
      export JRE_HOME=/home/vod/jdk/jdk1.8.0_191/jre
      export CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JRE_HOME/lib/tools.jar
      export PATH=$JAVA_HOME/bin:$PATH
    3. Run the :wq! command to save the file and exit.

  4. Run the java -version command to verify whether JDK has been installed.

    If the following JDK version information is displayed, the installation is successful:

    [root@ecs-c525-web ~]# java -version
    java version "1.8.0_191"
    Java(TM) SE Runtime Environment (build 1.8.0_191-b11)
    Java HotSpot(TM) 64-Bit Server VM (build 25.171-b11, mixed mode)