first step
- Check if your machine has jdk installed
java -version
yum list installed | grep [java][jdk]
- If so, please uninstall it first (as shown above)
- Uninstall
yum -y remove java-1.8.0-openjdk* //表时卸载所有openjdk相关文件输入
yum -y remove tzdata-java.noarch //卸载tzdata-java
Second step
- Install jdk
- View jdk version
yum search java | grep -i --color jdk
- Choose the version to install, or the second command is simple and rude
yum install -y java-1.8.0-openjdk java-1.8.0-openjdk-devel
yum install -y java-1.8.0-openjdk*
- Check if the installation is successful
java -version
third step
- Configure environment variables
- JDK default installation path /usr/lib/jvm
ls /usr/lib/jvm
- Add the following commands to the /etc/profile file
vim /etc/profile
JAVA_HOME=/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.242.b08-0.el7_7.x86_64
PATH=$PATH:$JAVA_HOME/bin
CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar
export JAVA_HOME CLASSPATH PATH
- Save and close the profile file, execute the following command to take effect
source /etc/profile
- Use the following command to view the JDK variables
echo $JAVA_HOME
echo $PATH
echo $CLASSPATH