What are the steps to install JDK on CentOS?
- Download the JDK installation package: Download the appropriate JDK installation package for CentOS from the Oracle official website or other trusted sources, such as JDK 8, JDK 11, etc.
- Copy the installation package to the CentOS server: Use the scp command to copy the downloaded JDK installation package to the appropriate directory on the CentOS server.
- Extract the installation package: Unzip the downloaded JDK installation package on the CentOS server using the following command.
tar -zxvf jdk-8u251-linux-x64.tar.gz
- To set environment variables, modify the .profile or .bashrc file on the CentOS server and add the following environment variables:
export JAVA_HOME=/path/to/jdk
export PATH=$JAVA_HOME/bin:$PATH
export CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar
Next, execute the following command to apply the environment variables.
source ~/.bashrc
- To verify the installation: Enter the following command in the terminal to check if JDK has been successfully installed:
java -version
If the installation is successful, the version information of JDK will be displayed.