/**PageBeginHtml Block Begin **/ /***自定义返回顶部小火箭***/ /*生成博客目录的JS 开始*/ /*生成博客目录的JS 结束*/

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 ~]#

image



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 ~]#

复制代码

image


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 查看卸载情况:

[root@localhost ~]# 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 ~]#

image

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]#

复制代码

image




解压 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

[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]#
View Code

image

5、设置环境变量

修改配置文件/etc/profile,配置JDK相关的环境变量

记得备份下/etc/profile文件

[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]#

View Code
[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

image

6、执行profile文件

[root@localhost software]# source /etc/profile

这样可以使配置不用重启即可立即生效。

image

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位的程序,所以重新下包操作上面流程即可。

image


9、查看Linux内核版本命令,两种方法都可以

输入:cat /proc/version

输入:uname -a




posted @ 2022-05-18 09:34  一品堂.技术学习笔记  阅读(1122)  评论(0编辑  收藏  举报