This is the third day of my participation in the August More text Challenge. For details, see: August More Text Challenge
If ❤️ my article is helpful, welcome to like, follow. This is the greatest encouragement for me to continue my technical creation. More past articles in my personal column
Yum download install
Use yum -y List Java or yum Search JDK to find a list of java-related installation packages
Yum -y list Java search
# yum -y list search demo$ yum -y list java Loaded plugins: fastestmirror Loading mirror speeds from cached hostfile * base: mirrors.aliyun.com * updates: Mirrors.aliyun.com Available Packages java-1.6.0-openjdk.x86_64 1.1.6.0.41-1.13.13.1.el7... mirrors.aliyun.com Available Packages Java-1.6.0-openjdk.x86_64 1.1.6.0.41-1.13.13.1.el7... Java - 1.8.0 comes with - its - headless. X86_64 l: 1.8.0.212. B04-0. El7_6 Java - 1.8.0 comes with - its. X86_64 1:1. 8.0.212. B04-0. El7_6# yum search JDK search demo$ yum search jdk ====================================== N/S matched: jdk ====================================== copy-jdk-configs.noarch : JDKs Configuration Files Copier Java-1.8.0-openjdk.i686: OpenJDK Runtime Environment 8... java-11-openjdk-debug.x86_64 : OpenJDK Runtime Environment 11 with full debug onCopy the code
Install the JDK
Select a JDK version from the above list and do the actual installation
$yum install java-1.8.0-openjdk.x86_64 Installed: Java - 1.8.0 comes with - its. X86_64 1:1. 8.0.292. B10-1. El7_9 Dependency Installed: Atk. X86_64 0:2.28.1-2.el7 copy-jdk-configs. Noarch 0:3.3-10.el7_5 giflib.x86_64 0:4.1.6-9.el7 GTK - update - icon - cache. X86_64 3-0. 22.30-6. El7... Chkconfig.x86_64 0:1.7.6-1.el7 Dependency Updated: chkconfig.x86_64 0:1.7.6-1.el7 Complete!Copy the code
If the preceding information is displayed, JDK is successfully installed
Configure environment variables such as JAVA_HOME
The default directory for installing JDK through yum is /usr/lib/jvm
$ls -l /usr/lib/jvm total 0 drwxr-xr-x 3 root root 16 Aug 3 22:53 java-1.8.0-openjdk-1.8.0.292.b10-1.el7_9.x86_64 LRWXRWXRWX 1 root root 21 Aug 3 22:53 JRE -> /etc/alternatives/jre LRWXRWXRWX 1 root root 27 Aug 3 22:53 JRE-1.8.0 -> /etc/alternatives/jre_1.8.0 LRWXRWX 1 root root 35 Aug 3 22:53 JRE-1.8.0-openjdk -> /etc/alternatives/jre_1.8.0_openjdk LRWXRWXRWX 1 root root 51 Aug 3 22:53 Jre-1.8.0-openjdk-1.8.0.292.b10-1.el7_9.x86_64 Java-1.8.0-openjdk-1.8.0.292.b10-1.el7_9.x86_64 / JRE LRWXRWXRWX 1 root root 29 Aug 3 22:53 JRE-openjdk -> /etc/alternatives/jre_openjdkCopy the code
You need to add the JDK installation path to JAVA_HOME to the environment variable
Edit the file vi /etc/profile
At the end of the file add:
#set java environmentJAVA_HOME = / usr/lib/JVM/jre - 1.6.0 - its. X86_64 PATH =$PATH:$JAVA_HOME/bin
CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar
export JAVA_HOME CLASSPATH PATH
Copy the code
After modifying the file, run the./etc/profile or source /etc/profile command to make it take effect
Verification after installation is complete
After the configuration is complete, verify that the preceding configuration is successful. If the Java version information is displayed, the JDK is successfully installed
$ java -version
openjdk version "1.8.0 comes with _292"
OpenJDK Runtime Environment (build 1.8.0_292-b10)
OpenJDK 64-Bit Server VM (build 25.292-b10, mixed mode)
Copy the code
Error: No matching Packages to list
The preceding problem is usually caused by the timeout of accessing the centos foreign source during the search. Change into domestic yum source
Backup the original yum source before replacement,
cd /etc/yum.repos.d/
mv CentOS-Base.repo CentOS-Base.repo_bak
Copy the code
Replace domestic yum sources
# netease yum source:
wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.163.com/.help/CentOS7-Base-163.repo
yum clean all
yum makecache
# Alibaba Cloud yum
wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
yum clean all
yum makecache
# epel source
yum -y install epel-release
yum clean all
yum makecache
Copy the code
The above three sources basically meet the needs of the development of YUM sources