apt install JDK8 and set as the system default Java

For more articles, please click

1. Background

Recently reinstalled the system, the new system comes with JDK11, but my project uses JDK8, go online search to see many installation methods are to download the installation package and unzip the installation, personally feel that this method is too inconvenient, we prefer apt Why not install it directly with the apt tool?

这里是一段防爬虫文本,读者请忽略。
本文最先由Baldwin_Keepmind发表于CSDN,转载请注明出处。
作者博客地址:https://blog.csdn.net/shouchenchuan5253

2. apt install jdk8

2.1 Search jdk8 installation package

command:

apt-cache search java8

result:

openjdk-8-jdk - OpenJDK Development Kit (JDK)
openjdk-8-jdk-headless - OpenJDK Development Kit (JDK) (headless)
openjdk-8-jre - OpenJDK Java runtime, using Hotspot JIT
openjdk-8-jre-headless - OpenJDK Java runtime, using Hotspot JIT (headless)
default-jdk - Standard Java or Java compatible Development Kit
default-jdk-headless - Standard Java or Java compatible Development Kit (headless)
default-jre - Standard Java or Java compatible Runtime
default-jre-headless - Standard Java or Java compatible Runtime (headless)
openjdk-11-jdk - OpenJDK Development Kit (JDK)
openjdk-11-jdk-headless - OpenJDK Development Kit (JDK) (headless)
openjdk-11-jre - OpenJDK Java runtime, using Hotspot JIT
openjdk-11-jre-headless - OpenJDK Java runtime, using Hotspot JIT (headless)
baldwin@baldwin:~$ sudo apt-get install openjdk-8-jdk 

The results list the packages that exist in the installation package library. Choose the version you want to install.

2.2. Install the selected version

We chose the first one here: openjdk-8-jdk
installation command:

sudo apt-get install openjdk-8-jdk

result:

正在读取软件包列表... 完成
正在分析软件包的依赖关系树       
正在读取状态信息... 完成       
将会同时安装下列软件:
openjdk-8-jdk-headless openjdk-8-jre openjdk-8-jre-headless
建议安装:
openjdk-8-demo openjdk-8-source visualvm icedtea-8-plugin libnss-mdns fonts-ipafont-gothic fonts-ipafont-mincho fonts-wqy-microhei fonts-wqy-zenhei
fonts-indic
下列【新】软件包将被安装:
openjdk-8-jdk openjdk-8-jdk-headless openjdk-8-jre openjdk-8-jre-headless
升级了 0 个软件包,新安装了 4 个软件包,要卸载 0 个软件包,有 68 个软件包未被升级。
需要下载 37.2 MB 的归档。
解压缩后会消耗 141 MB 的额外空间。
您希望继续执行吗? [Y/n] y
获取:1 https://community-packages.deepin.com/deepin apricot/main amd64 openjdk-8-jre-headless amd64 8u212-b01-1~deb9u1 [27.3 MB]
获取:2 https://community-packages.deepin.com/deepin apricot/main amd64 openjdk-8-jre amd64 8u212-b01-1~deb9u1 [69.3 kB]                               
获取:3 https://community-packages.deepin.com/deepin apricot/main amd64 openjdk-8-jdk-headless amd64 8u212-b01-1~deb9u1 [8,247 kB]                     
获取:4 https://community-packages.deepin.com/deepin apricot/main amd64 openjdk-8-jdk amd64 8u212-b01-1~deb9u1 [1,649 kB]                              
已下载 37.2 MB,耗时 23秒 (1,636 kB/s)                                                                                                                
正在选中未选择的软件包 openjdk-8-jre-headless:amd64。
(正在读取数据库 ... 系统当前共安装有 239212 个文件和目录。)
准备解压 .../openjdk-8-jre-headless_8u212-b01-1~deb9u1_amd64.deb  ...
正在解压 openjdk-8-jre-headless:amd64 (8u212-b01-1~deb9u1) ...
正在选中未选择的软件包 openjdk-8-jre:amd64。
准备解压 .../openjdk-8-jre_8u212-b01-1~deb9u1_amd64.deb  ...
正在解压 openjdk-8-jre:amd64 (8u212-b01-1~deb9u1) ...
正在选中未选择的软件包 openjdk-8-jdk-headless:amd64。
准备解压 .../openjdk-8-jdk-headless_8u212-b01-1~deb9u1_amd64.deb  ...
正在解压 openjdk-8-jdk-headless:amd64 (8u212-b01-1~deb9u1) ...
正在选中未选择的软件包 openjdk-8-jdk:amd64。
准备解压 .../openjdk-8-jdk_8u212-b01-1~deb9u1_amd64.deb  ...
正在解压 openjdk-8-jdk:amd64 (8u212-b01-1~deb9u1) ...
正在设置 openjdk-8-jre-headless:amd64 (8u212-b01-1~deb9u1) ...
update-alternatives: 使用 /usr/lib/jvm/java-8-openjdk-amd64/jre/bin/clhsdb 来在自动模式中提供 /usr/bin/clhsdb (clhsdb)
update-alternatives: 使用 /usr/lib/jvm/java-8-openjdk-amd64/jre/bin/hsdb 来在自动模式中提供 /usr/bin/hsdb (hsdb)
update-alternatives: 使用 /usr/lib/jvm/java-8-openjdk-amd64/jre/bin/orbd 来在自动模式中提供 /usr/bin/orbd (orbd)
update-alternatives: 使用 /usr/lib/jvm/java-8-openjdk-amd64/jre/bin/servertool 来在自动模式中提供 /usr/bin/servertool (servertool)
update-alternatives: 使用 /usr/lib/jvm/java-8-openjdk-amd64/jre/bin/tnameserv 来在自动模式中提供 /usr/bin/tnameserv (tnameserv)
正在设置 openjdk-8-jre:amd64 (8u212-b01-1~deb9u1) ...
update-alternatives: 使用 /usr/lib/jvm/java-8-openjdk-amd64/jre/bin/policytool 来在自动模式中提供 /usr/bin/policytool (policytool)
正在设置 openjdk-8-jdk-headless:amd64 (8u212-b01-1~deb9u1) ...
update-alternatives: 使用 /usr/lib/jvm/java-8-openjdk-amd64/bin/idlj 来在自动模式中提供 /usr/bin/idlj (idlj)
update-alternatives: 使用 /usr/lib/jvm/java-8-openjdk-amd64/bin/wsimport 来在自动模式中提供 /usr/bin/wsimport (wsimport)
update-alternatives: 使用 /usr/lib/jvm/java-8-openjdk-amd64/bin/jsadebugd 来在自动模式中提供 /usr/bin/jsadebugd (jsadebugd)
update-alternatives: 使用 /usr/lib/jvm/java-8-openjdk-amd64/bin/native2ascii 来在自动模式中提供 /usr/bin/native2ascii (native2ascii)
update-alternatives: 使用 /usr/lib/jvm/java-8-openjdk-amd64/bin/javah 来在自动模式中提供 /usr/bin/javah (javah)
update-alternatives: 使用 /usr/lib/jvm/java-8-openjdk-amd64/bin/jhat 来在自动模式中提供 /usr/bin/jhat (jhat)
update-alternatives: 使用 /usr/lib/jvm/java-8-openjdk-amd64/bin/xjc 来在自动模式中提供 /usr/bin/xjc (xjc)
update-alternatives: 使用 /usr/lib/jvm/java-8-openjdk-amd64/bin/schemagen 来在自动模式中提供 /usr/bin/schemagen (schemagen)
update-alternatives: 使用 /usr/lib/jvm/java-8-openjdk-amd64/bin/extcheck 来在自动模式中提供 /usr/bin/extcheck (extcheck)
update-alternatives: 使用 /usr/lib/jvm/java-8-openjdk-amd64/bin/wsgen 来在自动模式中提供 /usr/bin/wsgen (wsgen)
正在处理用于 bamfdaemon (0.5.4-1) 的触发器 ...
Rebuilding /usr/share/applications/bamf-2.index...
正在处理用于 desktop-file-utils (0.23-4) 的触发器 ...
正在处理用于 mime-support (3.62) 的触发器 ...
正在处理用于 hicolor-icon-theme (0.17-2) 的触发器 ...
正在处理用于 dde-daemon (5.9.5+c1-1) 的触发器 ...
正在处理用于 lastore-daemon (5.0.6-1) 的触发器 ...
正在处理用于 libc-bin (2.28.7-1+deepin) 的触发器 ...
正在设置 openjdk-8-jdk:amd64 (8u212-b01-1~deb9u1) ...
update-alternatives: 使用 /usr/lib/jvm/java-8-openjdk-amd64/bin/appletviewer 来在自动模式中提供 /usr/bin/appletviewer (appletviewer)

Wait for the installation to complete

2.3. Change the system preferred java version

Run the command to check the current java version:

baldwin@baldwin:~$ java -version
openjdk version "11.0.4" 2019-07-16
OpenJDK Runtime Environment (build 11.0.4+11-post-Debian-1deb10u1)
OpenJDK 64-Bit Server VM (build 11.0.4+11-post-Debian-1deb10u1, mixed mode, sharing)

It can be seen that the current preferred version is still jdk11

Change the preferred java version:
In fact, after installing jdk8, the last line has given a hint

update-alternatives: 使用 /usr/lib/jvm/java-8-openjdk-amd64/bin/appletviewer 来在自动模式中提供 /usr/bin/appletviewer

View the assigned java:

baldwin@baldwin:~$ sudo update-alternatives --list java
/usr/lib/jvm/java-11-openjdk-amd64/bin/java
/usr/lib/jvm/java-8-openjdk-amd64/jre/bin/java

During the download process, jdk8: java has been automatically added

View java priority:

baldwin@baldwin:~$ update-alternatives --display java
java - 自动模式
最佳链接版本为 /usr/lib/jvm/java-11-openjdk-amd64/bin/java
链接目前指向 /usr/lib/jvm/java-11-openjdk-amd64/bin/java
链接 java 指向 /usr/bin/java
从链接 java.1.gz 指向 /usr/share/man/man1/java.1.gz
/usr/lib/jvm/java-11-openjdk-amd64/bin/java - 优先级 1111
次要 java.1.gz:/usr/lib/jvm/java-11-openjdk-amd64/man/man1/java.1.gz
/usr/lib/jvm/java-8-openjdk-amd64/jre/bin/java - 优先级 1081
次要 java.1.gz:/usr/lib/jvm/java-8-openjdk-amd64/jre/man/man1/java.1.gz

Switch jdk version :

sudo update-alternatives --config java

Will list the optional jdk version and provide options

有 2 个候选项可用于替换 java (提供 /usr/bin/java)。

选择       路径                                          优先级  状态
------------------------------------------------------------
0            /usr/lib/jvm/java-11-openjdk-amd64/bin/java      1111      自动模式
1            /usr/lib/jvm/java-11-openjdk-amd64/bin/java      1111      手动模式
2            /usr/lib/jvm/java-8-openjdk-amd64/jre/bin/java   1081      手动模式

要维持当前值[*]请按<回车键>,或者键入选择的编号:2
update-alternatives: 使用 /usr/lib/jvm/java-8-openjdk-amd64/jre/bin/java 来在手动模式中提供 /usr/bin/java (java)

We chose the second one, now check the jdk version:

baldwin@baldwin:~$ java -version
openjdk version "1.8.0_212"
OpenJDK Runtime Environment (build 1.8.0_212-8u212-b01-1~deb9u1-b01)
OpenJDK 64-Bit Server VM (build 25.212-b01, mixed mode)

Deal!!!

这里是一段防爬虫文本,读者请忽略。
本文最先由Baldwin_Keepmind发表于CSDN,转载请注明出处。
作者博客地址:https://blog.csdn.net/shouchenchuan5253

3. Summary

I am a lazy person. I think the habit of being lazy allows me to learn more knowledge in work and life, and we can do more in the least amount of time.

Without the author's permission, it is strictly prohibited to reprint this article

I ’m Baldwin, a 25-year-old programmer dedicated to making learning more fun. If you really love programming, I sincerely hope to make a friend with you and wander in the sea of ​​programming together!

Good article in the past:

Spring source code analysis-MVC initialization

Spring breeze complacent horseshoe disease, read a article (JVM) virtual machine

The art of making wheels

Source reading skills

Detailed Java annotations

Teach you to build your own SpringBoot server

For more articles, please click

发布了66 篇原创文章 · 获赞 1603 · 访问量 28万+

Guess you like

Origin blog.csdn.net/shouchenchuan5253/article/details/105679621