You can search the Debian packages site and find out the openjdk-8-jdk package for Debian 10 is only available from unstable (sid) repository currently.
At first it is good to check and save current system-wide symbolic links for already installed Java SDK/JRE packages if any:
ls -la /etc/alternatives | grep java > previous-java-alternatives.txt
Then check is this package can be installed with current configuration:
apt-cache policy openjdk-8-jdk
If no then you need to add unstable repository to the sources list.
The negative output may imply that you prefer to use stable repositories and usually it isn't appropriate for you to update all other software from unstable repositories.
So before adding unstable repository to the sources list make sure APT::Default-Release configuration option is set to "stable":
grep -r Default-Release /etc/apt/
If no (as by default) then set it as recommended in that answer by creating this file:
/etc/apt/apt.conf.d/99defaultrelease
APT::Default-Release "stable";
Now you're ready to add the unstable repository to the sources list.
Before I prefer to check what mirror was selected by me when system was installed. Just look to main sources list:
cat /etc/apt/sources.list
In my case the output shows that mirror.yandex.ru server is used as system source. So I use the same for unstables and add this file:
/etc/apt/sources.list.d/91-debian-unstable.list
deb http://mirror.yandex.ru/debian/ unstable main
deb-src http://mirror.yandex.ru/debian/ unstable main
(I also have 90-debian-testing.list file for the testing repo.)
Then update package lists:
apt update
And check you system wont update from unstable sources:
apt list --upgradable
And recheck is required package can be installed:
apt-cache policy openjdk-8-jdk
Do install the package:
apt install openjdk-8-jdk
Look at new symbolic links:
ls -la /etc/alternatives | grep java-8
Just waste few seconds on them (or continue with man 1 update-alternatives).
I needed to install a 32-bit version but this wasn't available at adoptopenjdk far as I could see. I tracked down a copy of a binary at java.com i their downloads area:
jre-8u241-linux-i586.tar.gz
All I needed was the JRE (rather than a JDK, but the process should be the same for either) and since it was also for a personal use only, the Oracle binary was OK (they have limitations in this regard).
I downloaded the binary and placed it in the home folder (~/) of the user that needed to run it and then unzipped it like so:
mkdir ~/java && cd ~/java && tar -xf jre-8u241-linux-i586.tar.gz
Then added the location to the path of the user that would run the Java application by appending this line to ~/.profile:
This worked fine for my case but there are no doubt better ways to install a binary. For example so it is available for all Unix users rather than just one.
This is my script which I use to install OpenJDK 8 on Bitbucket's Pipelines Docker image NodeJS 10.16.2.
But now I see that this docker image is based on Stretch...
Based one some of the above answers, this is what i used in my shell script on debian buster silm os running node 12.x (node:12.6-buster-slim)
This was in preparing to move to github actions local testing with act, do note that there is no need for sudo as ci testing in this container already is root.
apt-get update -qq
#software-properties-common not installed on slim
apt-get install software-properties-common -y -q
wget -qO - https://adoptopenjdk.jfrog.io/adoptopenjdk/api/gpg/key/public | apt-key add -
add-apt-repository --yes https://adoptopenjdk.jfrog.io/adoptopenjdk/deb/
apt-get update -qq
#man folder needs to be available for adoptopenjdk-8 to finish configuring
mkdir -p /usr/share/man/man1/
apt-get install adoptopenjdk-8-hotspot -y
#ensure openjdk-8-jdk is found for some installations, thanks b8kich for the virtual wrapper
curl https://gitlab.com/b8kich/adopt-openjdk-8-jdk/-/raw/master/adopt-openjdk-8-jdk_0.1_all.deb?inline=false -o adopt-openjdk-8-jdk_0.1_all.deb
dpkg -i adopt-openjdk-8-jdk_0.1_all.deb
I've found, mainly after years of working with deprecated iDrac consoles which have particular java requirements, that installing multiple versions of the JRE or JDK is preferable as you can choose between them as necessary without worrying about other dependencies or breaking your package manager.
This is actually incredibly easy on Debian, and very probably other linux, by eschewing the package manager all together and manually installing whatever versions you need.
I selected "Java SE 8 (8u211 and later)" from the menu and snagged jre-8u271-linux-x64.tar.gz.
From there, extract the archive to a location accessible to the user who will be running java; Typically I'll extract to "/usr/local/lib/jre1.8.0_271/".
From here you can run /usr/local/lib/jre1.8.0_271/bin/java successfully, as well as javaws.
/usr/local/lib/jre1.8.0_271/bin# ./java -version
java version "1.8.0_271"
Java(TM) SE Runtime Environment (build 1.8.0_271-b09)
Java HotSpot(TM) 64-Bit Server VM (build 25.271-b09, mixed mode)
On most of my systems I already have some packaged version of jre installed that's native to the release, so my /usr/bin/java and /usr/bin/javaws typically are symlinks to /etc/alternatives/java /etc/alternatives/javaws, respectively.
To switch the system to a particular jre, just update the relevant symlinks to point to the version of your choice:
rm /usr/bin/java /usr/bin/javaws /usr/bin/jjs /usr/bin/jcontrol
for i in java javaws jjs jcontrol; do ln -s /usr/local/lib/jre1.8.0_271/bin/$i /usr/bin/$i; done
Note that if you need, per say, jre 7, 11 and 17 you can download and extract each version to a particular named folder in /usr/local/lib, or your home directory if you'll be launching it manually, and utilize each of them individually as needed by updating the symlinks or just running them directly.
I just faced a similar problem:
I have on old HP-mini 210 netbook to be used as a "car logger" and it has to use java 8 32bit (required by the logger application).
I'm running a light distro based on Debian 10 (BunsenLabs Lithyum).
After poking around the easyest way I found to install java 8 32bits was by using an openjdk 8 deb package published by OpenLogic (they have 32 or 64 bits):
https://www.openlogic.com/openjdk-downloads
Just download and install (package manager). Worked 100% and now I have a super fast hp-mini "car logger".