如何在Debian 10 (Buster)安装openjdk-8-jdk | Java Debug 笔记

780 阅读1分钟

本文正在参加「Java主题月 - Java Debug笔记活动」,详情查看 活动链接

如何在Debian 10 (Buster)安装openjdk-8-jdk

由于安全问题,Debian似乎不再支持openjdk-8-jdk。为Debian 10(Buster)安装openjdk-8-jdk的最简单方法是什么?

回答一

另外,你可以使用adoptopenjdk仓库:

wget -qO - https://adoptopenjdk.jfrog.io/adoptopenjdk/api/gpg/key/public | sudo apt-key add -

sudo add-apt-repository --yes https://adoptopenjdk.jfrog.io/adoptopenjdk/deb/

sudo apt-get update && sudo apt-get install adoptopenjdk-8-hotspot

adoptopenjdk.net/installatio…

回答二

这是我的脚本,我使用它在Bitbucket's Pipelines Docker image NodeJS 10.16.2里安装OpenJDK 8。但是现在看到这个docker镜像是基于Stretch的…

它基于github.com/docker-libr…

#!/bin/bash
set -x #echo on
# based on https://github.com/docker-library/openjdk/blob/89851f0abc3a83cfad5248102f379d6a0bd3951a/8-jdk/Dockerfile

apt-get update && apt-get install -y --no-install-recommends \
  bzip2 \
  unzip \
  xz-utils &&
  rm -rf /var/lib/apt/lists/*

echo 'deb http://httpredir.debian.org/debian-security stretch/updates main' >/etc/apt/sources.list.d/jessie-backports.list

# Default to UTF-8 file.encoding
export LANG=C.UTF-8

# add a simple script that can auto-detect the appropriate JAVA_HOME value
# based on whether the JDK or only the JRE is installed
{ \
    echo '#!/bin/sh'; \
    echo 'set -e'; \
    echo; \
    echo 'dirname "$(dirname "$(readlink -f "$(which javac || which java)")")"'; \
} > /usr/local/bin/docker-java-home \
&& chmod +x /usr/local/bin/docker-java-home

export JAVA_HOME=/usr/lib/jvm/java-8-openjdk-amd64
export JAVA_VERSION=8u252
export JAVA_DEBIAN_VERSION=8u252-b09-1~deb9u1

# see https://bugs.debian.org/775775
# and https://github.com/docker-library/java/issues/19#issuecomment-70546872
export CA_CERTIFICATES_JAVA_VERSION=20170929~deb9u3

set -x \
    && apt-get update \
    && apt-get install -y \
        openjdk-8-jdk="$JAVA_DEBIAN_VERSION" \
        ca-certificates-java="$CA_CERTIFICATES_JAVA_VERSION" \
    && rm -rf /var/lib/apt/lists/* \
    && [ "$JAVA_HOME" = "$(docker-java-home)" ]

# see CA_CERTIFICATES_JAVA_VERSION notes above
/var/lib/dpkg/info/ca-certificates-java.postinst configure

更新:

版本升级了。下面是最新的脚本hub.docker.com/layers/node…

#!/bin/bash
set -x #echo on
# based on https://github.com/docker-library/openjdk/blob/89851f0abc3a83cfad5248102f379d6a0bd3951a/8-jdk/Dockerfile

apt-get update && apt-get install -y --no-install-recommends \
  bzip2 \
  unzip \
  xz-utils &&
  rm -rf /var/lib/apt/lists/*

echo 'deb http://httpredir.debian.org/debian-security stretch/updates main' >/etc/apt/sources.list.d/jessie-backports.list

# Default to UTF-8 file.encoding
export LANG=C.UTF-8

# add a simple script that can auto-detect the appropriate JAVA_HOME value
# based on whether the JDK or only the JRE is installed
{ \
    echo '#!/bin/sh'; \
    echo 'set -e'; \
    echo; \
    echo 'dirname "$(dirname "$(readlink -f "$(which javac || which java)")")"'; \
} > /usr/local/bin/docker-java-home \
&& chmod +x /usr/local/bin/docker-java-home

export JAVA_HOME=/usr/lib/jvm/java-8-openjdk-amd64
export JAVA_VERSION=8u265
export JAVA_DEBIAN_VERSION=8u265-b01-0+deb9u1

# see https://bugs.debian.org/775775
# and https://github.com/docker-library/java/issues/19#issuecomment-70546872
export CA_CERTIFICATES_JAVA_VERSION=20170929~deb9u3

set -x \
    && apt-get update \
    && apt-get install -y \
        openjdk-8-jdk="$JAVA_DEBIAN_VERSION" \
        ca-certificates-java="$CA_CERTIFICATES_JAVA_VERSION" \
    && rm -rf /var/lib/apt/lists/* \
    && [ "$JAVA_HOME" = "$(docker-java-home)" ]

# see CA_CERTIFICATES_JAVA_VERSION notes above
/var/lib/dpkg/info/ca-certificates-java.postinst configure

文章翻译自Stack Overflow:stackoverflow.com/questions/5…