CentOS Exploration Road 2 --- Install JDK with rpm

Install jdk using rpm

​ In the previous Linux exploration article http://www.cnblogs.com/Kidezyq/p/8782728.html , there are yumcommands to install native OpenJDK through instructions. At that time, a great god commented, suggesting that it is best to install sun's JDK. I searched the Internet for the difference between JDK and OpenJDK. Generally speaking, OpenJDK can be considered as a simplified version of JDK. For specific differences, please refer to this Zhihu question: https://www.zhihu.com/question/19646618

​ Not much to say, here is the process of re-installing sun's JDK using rpm after installing OpenJDK:

  • Find the currently installed JDK : Executerpm -qa|grep jdk

  • Uninstall the installed JDK : For the jdk-related installation package found in the previous part, use yum -y remove java XXXXXto uninstall

  • Download the rpm package of sunJDK : directly download the rpm installation package of JDK from the official website of oracle. I started to execute it here. As a wget http://download.oracle.com/otn-pub/java/jdk/8u171-b11/512cd62ec5174c3487ac17c61aaa89e8/jdk-8u171-linux-x64.rpmresult, the downloaded package is very small, which is obviously wrong. Later, I simply downloaded it directly to the local PC, and then rz jdk-8u171-linux-x64.rpmuploaded it to the CentOS server through the command

  • Use the rmp command to install : Go directly to the folder where the rpm file is located and run as rootrpm -ihv jdk-8u171-linux-x64.rpm

  • Set JAVA-related environment variables : After the previous steps, I can directly input javaand javacexecute commands correctly. However, it is necessary to set environment variables when looking at the Internet. In order to prevent various unknown errors in the future, they are also set here. Execute under root: vi /etc/profile, add the following configuration at the end of the file:

  export JAVA_HOME=/usr/java/jdk1.8.0_171-amd64
  export CLASSPATH=.:$JAVA_HOME/jre/lib/rt.jar:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar
  export PATH=$JAVA_HOME/bin:$PATH
  • Enable environment variable configuration : executetouch /etc/profile

​Tips

1. rpm命令的相关参数说明:
 -a:查询所有套件;
-b<完成阶段><套件档>+或-t <完成阶段><套件档>+:设置包装套件的完成阶段,并指定套件档的文件名称;
-c:只列出组态配置文件,本参数需配合"-l"参数使用;
-d:只列出文本文件,本参数需配合"-l"参数使用;
-e<套件档>或--erase<套件档>:删除指定的套件;
-f<文件>+:查询拥有指定文件的套件;
-h或--hash:套件安装时列出标记;
-i:显示套件的相关信息;
-i<套件档>或--install<套件档>:安装指定的套件档;
-l:显示套件的文件列表;
-p<套件档>+:查询指定的RPM套件档;
-q:使用询问模式,当遇到任何问题时,rpm指令会先询问用户;
-R:显示套件的关联性信息;
-s:显示文件状态,本参数需配合"-l"参数使用;
-U<套件档>或--upgrade<套件档>:升级指定的套件档;
-v:显示指令执行过程;
-vv:详细显示指令执行过程,便于排错。

2. 如何查找rpm安装软件所在的路径:
a. 首先通过`rpm -qa|grep jdk` 找到通过rpm安装的jdk
b. 再通过`rpm -ql XXX`查找即可

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324876384&siteId=291194637