Since the centos installation comes with openjdk, you need to uninstall it and install your own jdk
Uninstall the jdk that comes with centos
1. Find java: rpm -qa | grep java
2. When uninstalling, it prompts that the permission is not enough, enter the root directory (the password is usually the same as the general user password): su - root
3. Uninstall other java files except .noarch files: rpm -e --nodeps java filename. If it is still not deleted, try to use the yum -y remove command (not tested personally)
4. Switch back to normal user: su - normal username
Note: After executing su root, the shell environment is still the normal user environment, and after su - root, the shell environment is the root environment. You can use echo $PATH to view the difference in environment variables under each operation
Install your own jdk
1. Enter the official website to download (note whether the operating system is 32-bit or 64-bit)
2. Create the java folder: mkdir /usr/java
3. Use the rz -E command to upload the downloaded jdk to centos (the .tar.gz file is downloaded here)
4. Unzip and install jdk: tar -zxvf jdk file full name
5. Backup environment variables: cp /etc/profile backup file name
6. Configure environment variables: vi /etc/profile, click "i", enter the following code, click the esc exit key, and enter ":wq" (be careful not to have spaces)
JAVA_HOME=/usr/java/jdk1.8.0_171
CLASSPATH=.:${JAVA_HOME}/lib/tools.jar
PATH=$PATH:${JAVA_HOME}/bin
export JAVA_HOME CLASSPATH PATH
7. Execute source /etc/profile to make environment variables take effect
8. Execute java -version to see if the configuration is successful
Reference: https://www.cnblogs.com/alwayswyy/p/5212471.html