如何在ubuntu 14.04 的docker镜像中安装oracle-java8-installer

如何在ubuntu 14.04 的docker镜像中安装oracle-java8-installer

Motivation

有一个项目建立在14.04,是以virtualbox虚拟机的形式给出的,我想要制作一个docker的镜像。在制作过程中需要安装oracle-java8-installer

Steps

由于docker的ubuntu 14.04镜像中缺少很多东西,我们需要一点点补齐。

安装add-apt-repository

这里参考 add-apt-repository:command not found 问题,我们需要进行以下两个步骤:

sudo apt-get install python-software-properties
sudo apt-get install software-properties-common

这样就安装好了

安装源

由于oracle权限变动的原因,webupd8team的源不能用了。因此我们用一个来自希腊的大学的源“Hellenic Schools Technical Support Team” team。但是他们的key里有希腊文,docker的ubuntu 14.04镜像默认用ascii码,因此我们要显式地指定编码。接下来我是在root账户中操作的,若非root用户,加上sudo即可

LC_ALL=C.UTF-8 add-apt-repository ppa:ts.sch.gr/ppa
apt-get update

下载包

先执行装包命令

apt-get install oracle-java8-installer

会进入一个可视化页面,一路选”是“即可。然后我们发现它开始下载一个tar包,速度巨慢有时候:

No /var/cache/oracle-jdk8-installer/wgetrc file found.
Creating /var/cache/oracle-jdk8-installer/wgetrc and
using default oracle-java8-installer wgetrc settings for it.
Downloading Oracle Java 8...
--2021-04-04 03:55:22--  https://github.com/frekele/oracle-java/releases/download/8u212-b10/jdk-8u212-linux-x64.tar.gz
Resolving github.com (github.com)... 52.74.223.119
Connecting to github.com (github.com)|52.74.223.119|:443... connected.
HTTP request sent, awaiting response... 302 Found
Location: https://github-releases.githubusercontent.com/100703446/34efb380-6318-11e9-8a83-2f52821e3788?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=AKIAIWNJYAX4CSVEH53A%2F20210404%2Fus-east-1%2Fs3%2Faws4_request&X-Amz-Date=20210404T035523Z&X-Amz-Expires=300&X-Amz-Signature=bf7fc775e55f4ff317703efcdf3cc68e98210734273cdb4b0162519ba194223c&X-Amz-SignedHeaders=host&actor_id=0&key_id=0&repo_id=100703446&response-content-disposition=attachment%3B%20filename%3Djdk-8u212-linux-x64.tar.gz&response-content-type=application%2Foctet-stream [following]
--2021-04-04 03:55:23--  https://github-releases.githubusercontent.com/100703446/34efb380-6318-11e9-8a83-2f52821e3788?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=AKIAIWNJYAX4CSVEH53A%2F20210404%2Fus-east-1%2Fs3%2Faws4_request&X-Amz-Date=20210404T035523Z&X-Amz-Expires=300&X-Amz-Signature=bf7fc775e55f4ff317703efcdf3cc68e98210734273cdb4b0162519ba194223c&X-Amz-SignedHeaders=host&actor_id=0&key_id=0&repo_id=100703446&response-content-disposition=attachment%3B%20filename%3Djdk-8u212-linux-x64.tar.gz&response-content-type=application%2Foctet-stream
Resolving github-releases.githubusercontent.com (github-releases.githubusercontent.com)... 185.199.110.154, 185.199.108.154, 185.199.109.154, ...
Connecting to github-releases.githubusercontent.com (github-releases.githubusercontent.com)|185.199.110.154|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 195013152 (186M) [application/octet-stream]
Saving to: 'jdk-8u212-linux-x64.tar.gz'

     0K ........ ........ ........ ........ ........ ........  1%  992K 3m9s
  3072K ........ ........ ........ ........ ........ ........  3% 94.4K 17m49s
  6144K ........ ........ ........

果断Ctrl+z中止掉。手动用迅雷或什么的去那个网址下载,传到指定的位置/var/cache/oracle-jdk8-installer/,然后重启实例重新输入命令安装即可。安装成功后就会见到以下内容:

Oracle JDK 8 installed

#####Important########
To set Oracle JDK8 as default, install the "oracle-java8-set-default" package.
E.g.: sudo apt install oracle-java8-set-default
On Ubuntu systems, oracle-java8-set-default is most probably installed
automatically with this package.
######################

我们检查一下安装情况:

root@93cfc4c286e7:~# java -version
java version "1.8.0_212"
Java(TM) SE Runtime Environment (build 1.8.0_212-b10)
Java HotSpot(TM) 64-Bit Server VM (build 25.212-b10, mixed mode)

安装完成

你可能感兴趣的:(Ubuntu,踩坑,docker,linux,ubuntu,java)