There are usually several ways to install jdk in CentOS 7 system:
This article demonstrates how to install via yum
yum search java|grep jdk
yum install java-1.8.0-openjdk
After the installation is complete, enter java -vsersion
to check whether the installation is successful
yum install java-1.8.0-openjdk-devel.x86_64
Use javac to test, the following text appears indicating that the installation is successful
Installing jdk through yum install will not automatically configure the JAVA_HOME environment variable. If some services rely on this environment variable, they will fail to start. The following demonstrates how to manually configure the JAVA_HOME environment variable.
which java
Output:/usr/bin/java
ls -lr /usr/bin/java
Output:/usr/bin/java ->/etc/alternatives/java
ls -lrt /etc/alternatives/java
Output:/etc/alternatives/java ->/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.242.b08-0.el7_7.x86_64/jre/bin/java
Find location:
/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.242.b08-0.el7_7.x86_64
vim /etc/profile
Add the following configuration inside
(The JAVA_HOME parameter is set according to the directory path found above)
export JAVA_HOME=/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.242.b08-0.el7_7.x86_64
# The above is the output of ls above, pay attention to remove the end/jre/bin/Java, if you do not follow the above steps exactly, you may need to change this
export JRE_HOME=$JAVA_HOME/jre
export CLASSPATH=$JAVA_HOME/lib:$JRE_HOME/lib:$CLASSPATH
export PATH=$JAVA_HOME/bin:$JRE_HOME/bin:$PATH
source /etc/profile
test
Execute: echo $JAVA_HOME
over ~~~
Recommended Posts