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.gz
extract to the current directory
4, vi /etc/profile
modify 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/profile
to update
7, used update-alternatives --display javac
to view the default priority OpenJDK; used update-alternatives --display java
to 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 java
to "+" under the java directory where you want to replace (before this directory should have "*"); the command sudo update-alternatives --config javac
to "+" under the directory where you want to replace the javac (before this directory should have "*" )
10, enter java -version can see
Step 9 is very important, most do not step 9 on Baidu, it will not cause how are replaced