[Linux] [memo] linux using OpenJDK JDK replacement process

Environment: CentOS7
installation package:jdk-8u231-linux-x64.tar.gz

First, install jdk

CentOS comes with OpenJDK, but OpenJDK only the most basic function, so it is better to install JDK

1, the current directory (Custom): /root/coding/java
 
2, rz(linux need to install lrzsz) upload windows download good jdk-8u231-linux-x64.tar.gz
 
3, enter the tar xzf jdk-8u231-linux-x64.tar.gzextract to the current directory
 
4, vi /etc/profilemodify the /etc/profilefile
 
5, append the following (which JAVA_HOME, JRE_HOME please according to their actual JDK installation path and version configuration)

set java environment
JAVA_HOME=/root/coding/java/jdk1.8.0_231
JRE_HOME=/root/coding/java/jdk1.8.0_231/jre
CLASS_PATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar:$JRE_HOME/lib
PATH=$PATH:$JAVA_HOME/bin:$JRE_HOME/bin
export JAVA_HOME JRE_HOME CLASS_PATH PATH

 
6, enter the command source /etc/profileto update
 
7, used update-alternatives --display javacto view the default priority OpenJDK; used update-alternatives --display javato view the default priority OpenJDK
 
8, redirection, covering OpenJDK
sudo update-alternatives --install /usr/bin/javac javac (你的javahome地址)bin/javac 2000000(高于OpenJDK优先度)
sudo update-alternatives --install /usr/bin/java java (你的javahome地址)/jre/bin/java 2000000(高于OpenJDK优先度)

sudo update-alternatives --install /usr/bin/javac javac /root/coding/java/jdk1.8.0_231/bin/javac 2000000
sudo update-alternatives --install /usr/bin/java java /root/coding/java/jdk1.8.0_231/jre/bin/java 2000000

 
9, the command sudo update-alternatives --config javato "+" under the java directory where you want to replace (before this directory should have "*"); the command sudo update-alternatives --config javacto "+" under the directory where you want to replace the javac (before this directory should have "*" )
A -9
 
10, enter java -version can seeA -10

Step 9 is very important, most do not step 9 on Baidu, it will not cause how are replaced

Published 11 original articles · won praise 96 · views 60000 +

Guess you like

Origin blog.csdn.net/weixin_42159233/article/details/105245017