Linux安装JDK完整步骤
Linux安装JDK完整步骤
1、检查一下系统中的jdk版本
[root@localhost software]# java -version
显示:
[root@localhost ~]# java -version
openjdk version "1.8.0_262"
OpenJDK Runtime Environment (build 1.8.0_262-b10)
OpenJDK 64-Bit Server VM (build 25.262-b10, mixed mode)
[root@localhost ~]#
2、检测jdk安装包
[root@localhost software]# rpm -qa | grep java
显示:
[root@localhost ~]# rpm -qa | grep java
javassist-3.16.1-10.el7.noarch
tzdata-java-2020a-1.el7.noarch
javapackages-tools-3.4.1-11.el7.noarch
javamail-1.4.6-8.el7.noarch
pki-base-java-10.5.18-7.el7.noarch
java-1.7.0-openjdk-1.7.0.261-2.6.22.2.el7_8.x86_64
java-1.8.0-openjdk-1.8.0.262.b10-1.el7.x86_64
java-1.8.0-openjdk-headless-1.8.0.262.b10-1.el7.x86_64
nuxwdog-client-java-1.0.5-1.el7.x86_64
java-1.7.0-openjdk-headless-1.7.0.261-2.6.22.2.el7_8.x86_64
python-javapackages-3.4.1-11.el7.noarch
[root@localhost ~]#
3、卸载openjdk
[root@localhost ~]# rpm -e --nodeps tzdata-java-2020a-1.el7.noarch
[root@localhost ~]# rpm -e --nodeps java-1.7.0-openjdk-1.7.0.261-2.6.22.2.el7_8.x86_64
[root@localhost ~]# rpm -e --nodeps java-1.8.0-openjdk-1.8.0.262.b10-1.el7.x86_64
[root@localhost ~]# rpm -e --nodeps java-1.8.0-openjdk-headless-1.8.0.262.b10-1.el7.x86_64
[root@localhost ~]# rpm -e --nodeps java-1.7.0-openjdk-headless-1.7.0.261-2.6.22.2.el7_8.x86_64
或者使用
[root@localhost jvm]# yum remove *openjdk*
之后再次输入rpm -qa | grep java 查看卸载情况:
javassist-3.16.1-10.el7.noarch
javapackages-tools-3.4.1-11.el7.noarch
javamail-1.4.6-8.el7.noarch
pki-base-java-10.5.18-7.el7.noarch
nuxwdog-client-java-1.0.5-1.el7.x86_64
python-javapackages-3.4.1-11.el7.noarch
[root@localhost ~]#
4、安装新的jdk
首先到jdk官网上下载你想要的jdk版本,下载完成之后将需要安装的jdk安装包放到Linux系统指定的文件夹下,并且命令进入该文件夹下:
官网下载最新稳定JDK:https://www.oracle.com/java/technologies/oracle-java-archive-downloads.html
注意:文件夹或文件没有执行权限时,记得修改其权限
[root@localhost Desktop]# pwd
/root/Desktop
[root@localhost Desktop]# ll
total 1860
-rw-r--r--. 1 root root 1904640 May 18 09:27 jdk-8u331-linux-i586.tar.gz
[root@localhost Desktop]#
解压 jdk-8u131-linux-x64.tar.gz安装包
[root@localhost software]# mkdir -p /usr/lib/jvm
[root@localhost Desktop]# chmod 777 /usr/lib/jvm [root@localhost software]# tar -zxvf jdk-8u131-linux-x64.tar.gz -C /usr/lib/jvm
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
[root@localhost Desktop]# pwd /root/Desktop [root@localhost Desktop]# ll total 1860 -rwxrwxrwx. 1 root root 1904640 May 18 09:27 jdk-8u331-linux-i586.tar.gz [root@localhost Desktop]# tar -zxvf jdk-8u331-linux-i586.tar.gz -C /usr/lib/jvm jdk1.8.0_331/ jdk1.8.0_331/COPYRIGHT jdk1.8.0_331/LICENSE jdk1.8.0_331/README.html jdk1.8.0_331/THIRDPARTYLICENSEREADME.txt jdk1.8.0_331/bin/ jdk1.8.0_331/bin/java-rmi.cgi jdk1.8.0_331/bin/appletviewer jdk1.8.0_331/bin/extcheck jdk1.8.0_331/bin/idlj jdk1.8.0_331/bin/jar jdk1.8.0_331/bin/jarsigner jdk1.8.0_331/bin/javac jdk1.8.0_331/bin/javadoc jdk1.8.0_331/bin/javah jdk1.8.0_331/bin/javap jdk1.8.0_331/bin/jdeps jdk1.8.0_331/bin/jconsole jdk1.8.0_331/bin/jdb jdk1.8.0_331/bin/jhat jdk1.8.0_331/bin/jinfo jdk1.8.0_331/bin/jmap jdk1.8.0_331/bin/jps jdk1.8.0_331/bin/jrunscript jdk1.8.0_331/bin/jjs jdk1.8.0_331/bin/jsadebugd jdk1.8.0_331/bin/jstack jdk1.8.0_331/bin/jstat jdk1.8.0_331/bin/jstatd jdk1.8.0_331/bin/keytool jdk1.8.0_331/bin/native2ascii jdk1.8.0_331/bin/policytool jdk1.8.0_331/bin/schemagen jdk1.8.0_331/bin/rmic jdk1.8.0_331/bin/serialver jdk1.8.0_331/bin/xjc jdk1.8.0_331/bin/wsgen jdk1.8.0_331/bin/wsimport jdk1.8.0_331/bin/orbd jdk1.8.0_331/bin/servertool jdk1.8.0_331/bin/tnameserv jdk1.8.0_331/bin/pack200 jdk1.8.0_331/bin/rmid jdk1.8.0_331/bin/rmiregistry jdk1.8.0_331/bin/jcmd jdk1.8.0_331/bin/java jdk1.8.0_331/bin/unpack200 jdk1.8.0_331/bin/javaws jdk1.8.0_331/bin/jcontrol jdk1.8.0_331/bin/ControlPanel jdk1.8.0_331/bin/jvisualvm jdk1.8.0_331/bin/javafxpackager jdk1.8.0_331/bin/javapackager jdk1.8.0_331/include/ jdk1.8.0_331/include/jdwpTransport.h jdk1.8.0_331/include/jni.h jdk1.8.0_331/include/jvmti.h jdk1.8.0_331/include/jvmticmlr.h jdk1.8.0_331/include/jawt.h jdk1.8.0_331/include/classfile_constants.h jdk1.8.0_331/include/linux/ jdk1.8.0_331/include/linux/jni_md.h jdk1.8.0_331/include/linux/jawt_md.h jdk1.8.0_331/jre/ jdk1.8.0_331/jre/bin/ jdk1.8.0_331/jre/bin/keytool jdk1.8.0_331/jre/bin/jjs jdk1.8.0_331/jre/bin/policytool jdk1.8.0_331/jre/bin/orbd jdk1.8.0_331/jre/bin/servertool jdk1.8.0_331/jre/bin/tnameserv jdk1.8.0_331/jre/bin/pack200 jdk1.8.0_331/jre/bin/rmid jdk1.8.0_331/jre/bin/rmiregistry jdk1.8.0_331/jre/bin/java jdk1.8.0_331/jre/bin/unpack200 jdk1.8.0_331/jre/bin/javaws jdk1.8.0_331/jre/bin/jcontrol jdk1.8.0_331/jre/bin/ControlPanel jdk1.8.0_331/jre/lib/ jdk1.8.0_331/jre/lib/i386/ jdk1.8.0_331/jre/lib/i386/libjsig.so jdk1.8.0_331/jre/lib/i386/server/ jdk1.8.0_331/jre/lib/i386/server/libjvm.so gzip: stdin: unexpected end of file tar: Unexpected EOF in archive tar: Unexpected EOF in archive tar: Error is not recoverable: exiting now [root@localhost Desktop]#
5、设置环境变量
修改配置文件/etc/profile,配置JDK相关的环境变量
记得备份下/etc/profile文件
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
[root@localhost jvm]# cd /home/
[root@localhost home]# mkdir Backup
[root@localhost home]# cp /etc/profile /home/Backup/
[root@localhost home]# ll ./Backup/
total 4
-rw-r--r--. 1 root root 1854 May 18 10:08 profile
[root@localhost home]#
[root@localhost home]# cd /usr/lib/jvm [root@localhost jvm]# pwd /usr/lib/jvm [root@localhost jvm]# ll total 0 drwxr-xr-x. 5 10143 10143 129 Mar 10 19:30 jdk1.8.0_331 [root@localhost jvm]#
[root@localhost software]# vim /etc/profile
在最前面添加:
export JAVA_HOME=/usr/lib/jvm/jdk1.8.0_331 export JRE_HOME=${JAVA_HOME}/jre export CLASSPATH=.:${JAVA_HOME}/lib:${JRE_HOME}/lib export PATH=${JAVA_HOME}/bin:$PATH
6、执行profile文件
[root@localhost software]# source /etc/profile
这样可以使配置不用重启即可立即生效。
7、检查新安装的jdk
[root@localhost software]# java -version
显示:
java version "1.8.0_131" Java(TM) SE Runtime Environment (build 1.8.0_131-b11) Java HotSpot(TM) 64-Bit Server VM (build 25.131-b11, mixed mode)
到此为止,整个安装过程结束。
8、问题处理
如果报错,可能是由于64位系统中安装了32位的程序,所以重新下包操作上面流程即可。
9、查看Linux内核版本命令,两种方法都可以
输入:cat /proc/version
输入:uname -a
学问:纸上得来终觉浅,绝知此事要躬行
为事:工欲善其事,必先利其器。
态度:道阻且长,行则将至;行而不辍,未来可期
.....................................................................
------- 桃之夭夭,灼灼其华。之子于归,宜其室家。 ---------------
------- 桃之夭夭,有蕡其实。之子于归,宜其家室。 ---------------
------- 桃之夭夭,其叶蓁蓁。之子于归,宜其家人。 ---------------
=====================================================================
* 博客文章部分截图及内容来自于学习的书本及相应培训课程以及网络其他博客,仅做学习讨论之用,不做商业用途。
* 如有侵权,马上联系我,我立马删除对应链接。 * @author Alan -liu * @Email no008@foxmail.com
转载请标注出处! ✧*꧁一品堂.技术学习笔记꧂*✧. ---> https://www.cnblogs.com/ios9/