The software installation methods of each Linux distribution are different. For example, Java, the installation under RedHat / CentOS adopts its own unique method.
Of course, the easiest way is to use yum to install.
Check the java version in the yum repository
At the command line, directly enter the following command to see which Java installation versions are available in the yum software repository.
yum search java | grep jdk
As you can see, under CentOS 7, there are versions of Java 1.6/1.7/1.8 available for installation.
select install
I want to install Java 1.8 here, so install it like this (install the runtime environment and development environment):
yum install java-1.8.0-openjdk java-1.8.0-openjdk-devel
set variable environment
Edit the environment configuration file /etc/profile:
vi /etc/profile
Add the following at the end:
#set java environment
JAVA_HOME=/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.161-0.b14.el7_4.x86_64
JRE_HOME=$JAVA_HOME/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
Then let the environment configuration take effect:
source /etc/profile
Verify the validity of the JDK
java -version