安装JDK8

官网下载获取JDK

Oracle官网JDK8下载地址
https://www.oracle.com/java/technologies/javase/javase-jdk8-downloads.html
CentOS7下安装配置JDK8 - 图1
选择Linux x64 Compressed Archive 点击 jdk-8u281-linux-x64.tar.gz 下载jdk8。
CentOS7下安装配置JDK8 - 图2下载时会要同意Oracle协议,点击打勾,然后再会要求登录Oracle账户。
CentOS7下安装配置JDK8 - 图3
输入用户名和密码,没有注册一个,点击登录后就可以下载jdk
CentOS7下安装配置JDK8 - 图4

wget命令获取JDK

也可以先登录然后选择在服务器下面用wget命令下载jdk。先从Oracle官网上选择要下载的jdk,然后再打开浏览器的开发者模式,查看要下载的jdk版本对应的链接 jdk-8u281-linux-x64.tar.gz,在Elements栏中能查看到a标签中有 data-flie 属性,点击复制属性这里是 //download.oracle.com/otn/java/jdk/8u281-b09/89d678f2be164786b292527658ca1605/jdk-8u281-linux-x64.tar.gz在前面加上http: 同时otn换成otn-pub
最终jdk8的下载地址为 http://download.oracle.com/otn-pub/java/jdk/8u281-b09/89d678f2be164786b292527658ca1605/jdk-8u281-linux-x64.tar.gz
CentOS7下安装配置JDK8 - 图5
然后用下载命令在服务下面下载jdk下载URL换成上面自己获取到的URL
wget —no-cookies —no-check-certificate —header “Cookie: gpw_e24=http%3A%2F%2Fwww.oracle.com%2F; oraclelicense=accept-securebackup-cookie” “http://download.oracle.com/otn-pub/java/jdk/8u281-b09/89d678f2be164786b292527658ca1605/jdk-8u281-linux-x64.tar.gz”
[root@jrpt-1 software]# wget —no-cookies —no-check-certificate —header “Cookie: gpw_e24=http%3A%2F%2Fwww.oracle.com%2F; oraclelicense=accept-securebackup-cookie” “http://download.oracle.com/otn-pub/java/jdk/8u281-b09/89d678f2be164786b292527658ca1605/jdk-8u281-linux-x64.tar.gz”
—2021-04-15 09:56:43— http://download.oracle.com/otn-pub/java/jdk/8u281-b09/89d678f2be164786b292527658ca1605/jdk-8u281-linux-x64.tar.gz
Resolving download.oracle.com (download.oracle.com)… 23.67.68.237
Connecting to download.oracle.com (download.oracle.com)|23.67.68.237|:80… connected.
HTTP request sent, awaiting response… 302 Moved Temporarily
Location: https://edelivery.oracle.com/otn-pub/java/jdk/8u281-b09/89d678f2be164786b292527658ca1605/jdk-8u281-linux-x64.tar.gz [following]
—2021-04-15 09:56:43— https://edelivery.oracle.com/otn-pub/java/jdk/8u281-b09/89d678f2be164786b292527658ca1605/jdk-8u281-linux-x64.tar.gz
Resolving edelivery.oracle.com (edelivery.oracle.com)… 184.26.251.178, 2600:140b:2:99b::366, 2600:140b:2:9a8::366
Connecting to edelivery.oracle.com (edelivery.oracle.com)|184.26.251.178|:443… connected.
HTTP request sent, awaiting response… 302 Moved Temporarily
Location: https://download.oracle.com/otn-pub/java/jdk/8u281-b09/89d678f2be164786b292527658ca1605/jdk-8u281-linux-x64.tar.gz?AuthParam=1618451925_477b68a45dd60daeb8d401ac070d84b1 [following]
—2021-04-15 09:56:44— https://download.oracle.com/otn-pub/java/jdk/8u281-b09/89d678f2be164786b292527658ca1605/jdk-8u281-linux-x64.tar.gz?AuthParam=1618451925_477b68a45dd60daeb8d401ac070d84b1
Connecting to download.oracle.com (download.oracle.com)|23.67.68.237|:443… connected.
HTTP request sent, awaiting response… 200 OK
Length: 143722924 (137M) [application/x-gzip]
Saving to: ‘jdk-8u281-linux-x64.tar.gz’

41% [====================================> ] 59,916,969 6.88MB/s eta 15s
[root@jrpt-1 software]# tar -zxvf jdk-8u281-linux-x64.tar.gz

gzip: stdin: not in gzip format
tar: Child returned status 1
tar: Error is not recoverable: exiting now
如果提示错误not in gzip format代表下载不是gzip文件,可能是html文件。
通过head命令查看,gzip文件里面会有很多乱码,而html文件直接是我们能看明白的东西。
[root@jrpt-1 software]# head jdk-8u281-linux-x64.tar.gz
�”?�”?�mմi��qU�n����|���݉v#+��xs��7oޛ�����~.�������xJ��1��G�G�z!���㣉����0�’FFD�>&yB���K)9���T�h�’���z’ĺS�l��S
��s��t��mg���Qi���Q�’F�#��o���O���k��}�e�x��:N
�W+Z�l}�q��{T+�L��|Ë)Iˢ�ʣ���yC�)J�lz�sJ���2R贀@��S�U
���0� 0m�^�A|�,”�G�C�c������p��oq��:5m߰,h�4 ��|ӱ)�V]缩CW��
{���SK[�9�֊Fէ�G��
�Y��+��ĦMם�K��r\E�,g����V�uj;>�6�W�@jR�໚�.���hzQ��Zqt��b�
P�̸P
��l��x%ǭ
�j��^y�A̪�k6ȯ�@<br /> �c��Fa]�v��1�3��ȰWL�0\�/�<�R�֑Dэ�S��7�S�~ж5
43|�f�uM�
�iZ+�z�P�”��:1@F���6e�5@z�V8
v��C�e�^1�U�/;5�
�b� ���
`��,T���t9����l��P�6��q�����Q֬�w��|H”#j�
p�
�qDQ8��gR���|�����R�tD:5c�����U�0��̩���Fe����\g
�.����1 �U��3qd%g���zf�bŰ��^�(�%� M�kC��)ӀA˚�K<;BJ��&���v��1�J�@��\���p�&8/.GpW�r��^<br /> ș��[��Iz�W+��1��kl1�z��\����Z�xP[��&�+[j��׼�Z��-<br /> �#�[2��f�%<br />$�u1�dn㞁Q��a;�1�N��a�c�x8�],G5�#�sP��%�|�l�y�5<br />� ��a�gk�<br />KZeèt��F����KlX��l�.
� ��qӒfZ��V��TЊ�jUܣt؁5p�f�)q��E�a5���)���1I��’Ja9�’p���
�+����]���<��O���>��MD%m�k�������
Ʈ��=����F��7t�i��*0 4(�7L�&�xÇ�:��JQ�
���2�]���Y B���,��{��w�P�Yq�B�E����0����ê�Yt:m�����3��_���H���B��,���-� ���!2� ��`�T8U@����K���T��djc T#}iЇ
ޤњ”�T�b�X�,4B��I؞�S8���\�TJ�S�u��,�2٪ir
��
建议先通过浏览器下载到本地再上传到服务器

安装配置JDK

先创建解压文件要放的路径
[root@jrpt-1 software]# mkdir -vp /usr/local/tools/java
mkdir: created directory ‘/usr/local/tools’
mkdir: created directory ‘/usr/local/tools/java’
将文件解压到对应目录
[root@jrpt-1 software]# tar -zxvf jdk-8u281-linux-x64.tar.gz -C /usr/local/tools/java/

配置环境变量

vim /etc/profile
将如下代码追加到 profile 文件末尾:
JAVA_HOME=/usr/local/tools/java/jdk1.8.0_281
JRE_HOME=$JAVA_HOME/jre
PATH=$PATH:$JAVA_HOME/bin:$JRE_HOME/bin
CLASSPATH=.:$JAVA_HOME/jre/lib/rt.jar:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar
export JAVA_HOME JRE_HOME PATH CLASSPATH
[root@jrpt-1 lib]# vim /etc/profile
CentOS7下安装配置JDK8 - 图6
使用配置生效
[root@jrpt-1 lib]# source /etc/profile

验证jdk已安装成功

确认java运行环境安装成功
[root@jrpt-1 lib]# java -version
java version “1.8.0_281”
Java(TM) SE Runtime Environment (build 1.8.0_281-b09)
Java HotSpot(TM) 64-Bit Server VM (build 25.281-b09, mixed mode)
确认java编译功能安装成功
[root@jrpt-1 lib]# javac
Usage: javac
where possible options include:
-g Generate all debugging info
-g:none Generate no debugging info
-g:{lines,vars,source} Generate only some debugging info
-nowarn Generate no warnings
-verbose Output messages about what the compiler is doing
-deprecation Output source locations where deprecated APIs are used
-classpath Specify where to find user class files and annotation processors
-cp Specify where to find user class files and annotation processors
-sourcepath Specify where to find input source files
-bootclasspath Override location of bootstrap class files
-extdirs Override location of installed extensions
-endorseddirs Override location of endorsed standards path
-proc:{none,only} Control whether annotation processing and/or compilation is done.
-processor [,,…] Names of the annotation processors to run; bypasses default discovery process
-processorpath Specify where to find annotation processors
-parameters Generate metadata for reflection on method parameters
-d Specify where to place generated class files
-s Specify where to place generated source files
-h Specify where to place generated native header files
-implicit:{none,class} Specify whether or not to generate class files for implicitly referenced files
-encoding Specify character encoding used by source files
-source Provide source compatibility with specified release
-target Generate class files for specific VM version
-profile Check that API used is available in the specified profile
-version Version information
-help Print a synopsis of standard options
-Akey[=value] Options to pass to annotation processors
-X Print a synopsis of nonstandard options
-J Pass directly to the runtime system
-Werror Terminate compilation if warnings occur
@ Read options and filenames from file