Install and uninstall jdk in linux

1. yum uninstall

  1. Check if the JDK is installed in CentOS yum list installed | grep java:; centos7 comes with openjdk by default, openjdk is not the official JDK of Oracle, is an open source JDK, the official is the JDK of Oracle: openjdk may have compatibility issues.
  2. If there is a built-in jdk, delete the JDK that comes with centos
    yum -y remove java-1.8.0-openjdk*
    yum -y remove tzdata-java.noarch
    
  3. The result is displayed as Complete! Indicates that the uninstallation is complete

2. Manual uninstall

  1. Find the installation path which java(check the JDK installation path)
  2. Delete the folder where jdk is located rm -rf ***(*** is the path found in the first step)
  3. vim command to edit the file profile vim /etc/profile; delete the environment variables to configure the JDK, so the JDK uninstall is complete

3. Install JDK

  1. Download the linux version of JDK from Oracle's official website and upload it to Linux
  2. Create a new java folder to decompress the downloaded JDK
    mkdir /usr/local/java
    tar -zxvf jdk1.8.*** 
    
  3. Configure environment variables
    vim /etc/profile 
    
    ## 在"HISTSIZE=1000"底下添加环境变量的路径:
    JAVA_HOME=/usr/local/java
    CLASSPATH=.:$JAVA_HOME/lib
    PATH=$JAVA_HOME/bin:$PATH
    JRE_HOME=$JAVA_HOME/jre
    
    ##在"export PATH USER LOGNAME MAIL HOSTNAME HISTSIZE INPUTRC"下面添加: 
    export JAVA_HOME PATH CLASSPATH JRE_HOME  
    
    ## 完成后保存退出,然后使配置生效   
    source /etc/profile  
    
  4. Set the symbolic connection of java and javac
    cd /usr/bin 
    ln -s -f /usr/local/java/jre/bin/java
    ln -s -f /usr/local/java/bin/javac
    
  5. Restart the system ( reboot), check whether the installation is successful
    echo $JAVA_HOME
    echo $PATH
    echo $CLASSPATH
    java -version
    

Guess you like

Origin www.cnblogs.com/huizhipeng/p/12728458.html