Linux中安装JDK1.8
因工作原因需要使用一台CentOS7.5 64位的服务器,因为是新装的系统,需要安装一些常用工具。
作为一名Java后端工程师肯定离不开JDK,这里我们首先来安装JDK1.8
从官网下载 jdk-8u202-linux-x64.tar.gz
, 为什么要下载这个版本?
免费可商用呗!
官网原文:
WARNING: These older versions of the JRE and JDK are provided to help developers debug issues in older systems. They are not updated with the latest security patches and are not recommended for use in production.
These Java SE 8 update releases are provided under the Binary Code License (“BCL”).
Java SE 8u211 and later updates are available, under the Java SE OTN License.
For production use Oracle recommends downloading the latest JDK and JRE versions and allowing auto-update.
Only developers and Enterprise administrators should download these releases.
Downloading these releases requires an oracle.com account. If you don't have an oracle.com account you can use the links on the top of this page to learn more about it and register for one for free.
For current Java releases, please consult the Oracle Software Download page.
Java SE Development Kit 8u202
This software is licensed under the Oracle Binary Code License Agreement for Java SE Platform Products
Oracle在2019年4月的时候,对Oracle JDK的License做了一次变更。
- Java SE 8u202及以前的版本,协议是: Binary Code License ("BCL").
- Java SE 8u211及以后的版本,协议是:Java SE OTN License.
后续,由于争议过大,Java SE 17及以后的JDK版本,又变更为 Oracle No-Fee Terms and Conditions License 协议了。
好吧,也许有点复杂,你会觉得非常绕。
简单来说就是:
- 无论是个人或企业商用,可以免费无偿使用Java SE 8u202及以前的版本,但已经没有安全及补丁更新了
- 一定条件下,如个人或开发阶段,可以免费无偿使用Java SE 8u211及后续的Java SE 11版本。其它如企业商用则需要付费才能使用。
- Java SE 17及之后的LTS版本,可以免费无偿使用,但有一定的支持期限,期限是下一个LTS版本发布之后延长一年。
说了这么多,我们来看看具体怎么安装。
1. 上传安装包
首先将安装包上传到 /home
目录:
[root@ecs-b8e8-1114079 home]# pwd
/home
[root@ecs-b8e8-1114079 home]# ls
jdk-8u202-linux-x64.tar.gz
上述命令中
pwd
用于显示当前工作目录的全路径为/home
,当在命令行中通过一系列cd
命令进 入某个路径后,不确定当前所在的位置时,可以通过pwd
命令查看当前目录的绝对路径。ls
用于列出当前目录下的所有文件和子目录,根据上面的输出结果可知当前目录下只有一个jdk-8u202-linux-x64.tar.gz
文件。
2. 解压安装包
输入 tar -xzvf jdk-8u202-linux-x64.tar.gz
解压安装文件压缩包:
[root@ecs-b8e8-1114079 home]# tar -xzvf jdk-8u202-linux-x64.tar.gz
jdk1.8.0_202/
jdk1.8.0_202/javafx-src.zip
jdk1.8.0_202/bin/
... 中间省略 n 行 ...
jdk1.8.0_202/jre/Welcome.html
jdk1.8.0_202/jre/README
jdk1.8.0_202/README.html
使用 ls -l
可以看到解压后多了 jdk1.8.0_202
这个文件夹
[root@ecs-b8e8-1114079 home]# ls -l
total 189500
drwxr-xr-x 7 10 143 4096 Dec 16 2018 jdk1.8.0_202
-rw-r--r-- 1 root root 194042837 Jul 28 18:38 jdk-8u202-linux-x64.tar.gz
3. 将JDK安装到/usr/java目录
使用 mkdir
命令创建目录 /usr/java
使用 mv
命令将解压后的 jdk1.8.0_202/
移动到新建目录 /usr/java/
:
[root@ecs-b8e8-1114079 home]# mkdir /usr/java
[root@ecs-b8e8-1114079 home]# mv jdk1.8.0_202/ /usr/java/
[root@ecs-b8e8-1114079 home]# cd /usr/java
[root@ecs-b8e8-1114079 java]# ll
total 4
drwxr-xr-x 7 10 143 4096 Dec 16 2018 jdk1.8.0_202