CentOS 7 yum installation and configuration of JDK detailed

first step

  • Check if your machine has jdk installed
java -version
yum list installed | grep [java][jdk]

Insert picture description here

  • 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

Insert picture description here

  • 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
#或者如下命令,安装jdk1.8.0的所有文件
yum install -y java-1.8.0-openjdk*

  • Check if the installation is successful
java -version

Insert picture description here

third step

  • Configure environment variables
  • JDK default installation path /usr/lib/jvm
ls /usr/lib/jvm

Insert picture description here

  • Add the following commands to the /etc/profile file
vim /etc/profile

# set java environment  
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

Insert picture description here

Guess you like

Origin blog.csdn.net/JISOOLUO/article/details/105029020