Edit 22-Jul-2019: This answer currently does not work. The below referenced JDK packages are no longer available on Debian Experimental. In any case, they lagged behind Ubuntu Trusty's packages which contained more recent security updates. Please refer to the other answers until this can be resolved (sorry, no ETA).
It does not look like the maintainer of openjdk-r/ppa will be updating the openjdk-7 package beyond version 7u95-2.6.4-3. That package's description "Copied from debian experimental in Primary Archive for Debian GNU/Linux" gives us a clue about how to handle this ourselves, though.
Option 1: Manual Installation
Download the packages intended for your architecture:
(for most users, this means amd64 if 64bit, or i386 if 32bit Ubuntu is installed)
(Attempt to) install the packages using dpkg
:
Ubuntu 17.10 and earlier:
sudo dpkg -i openjdk-7-* libjpeg62-turbo* libfontconfig1* fontconfig-config*
Ubuntu 18.04 and later:
sudo dpkg -i openjdk-7-* libjpeg62-turbo*
Check the output from dpkg
. If there were dependency problems – which is likely – you will see the following (with your architecture substituted for amd64):
Errors were encountered while processing:
openjdk-7-jre:amd64
openjdk-7-jre-headless:amd64
openjdk-7-jdk:amd64
If there were no dependency issues, great, you're done, skip to #4. Otherwise, if you need to resolve some dependency issues, this is handled with:
sudo apt install -f
Notice, there is no need to re-run dpkg
after letting apt
resolve dependencies. It will automatically finish installation of the openjdk packages.
Update java alternatives. You can view all installed java versions with update-java-alternatives --list
. To activate OpenJDK Java 1.7, run:
sudo update-java-alternatives -s java-1.7.0-openjdk-amd64
You may notice an error about the IcedTeaPlugin.so
plugin being unavailable. This isn't a real concern for developers working with the JDK.
Verify java is working:
java -version
which should output something similar to:
java version "1.7.0_161"
OpenJDK Runtime Environment (IcedTea 2.6.12) (7u161-2.6.12-1)
OpenJDK 64-Bit Server VM (build 24.161-b01, mixed mode)
Option 2: Automatic Installation (including updates with apt
)
Pinning can be utilized to install and update openjdk-7-jdk and its dependencies from Debian repositories.
Create a pinning file that tells apt
to only consider packages that interest us (we certainly don't want our entire Ubuntu distribution "upgraded" with Debian experimental packages).
Create file /etc/apt/preferences.d/debian
with the below contents. You'll need superuser privileges, so use one of sudo vim
, sudo nano
, gksudo gedit
, etc.
Package: *
Pin: release o=Debian,n=experimental
Pin-Priority: -1
Package: *
Pin: release o=Debian,n=sid
Pin-Priority: -1
Package: openjdk-7-jdk
Pin: release o=Debian,n=experimental
Pin-Priority: 500
Package: openjdk-7-jre
Pin: release o=Debian,n=experimental
Pin-Priority: 500
Package: openjdk-7-jre-headless
Pin: release o=Debian,n=experimental
Pin-Priority: 500
Package: libjpeg62-turbo
Pin: release o=Debian,n=sid
Pin-Priority: 500
For Ubuntu 17.10 and earlier, also append the following (and see note at bottom):
Package: libfontconfig1
Pin: release o=Debian,n=sid
Pin-Priority: 500
Package: fontconfig-config
Pin: release o=Debian,n=sid
Pin-Priority: 500
Install the Debian keyring:
sudo apt install debian-archive-keyring
Note: while this is the simplest method of adding the debian keyring, it may not be up to date. Check for output like the following when running apt update
in step 4:
W: GPG error: http://cdn-fastly.deb.debian.org/debian experimental InRelease: The following signatures couldn't be verified because the public key is not available: NO_PUBKEY 8B48AD6246925553 NO_PUBKEY 7638D0442B90D010
E: The repository 'http://httpredir.debian.org/debian experimental InRelease' is not signed.
If you see this error, then manually add the necessary keys with:
sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 8B48AD6246925553
sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 7638D0442B90D010
where 8B48AD6246925553
and 7638D0442B90D010
should match the pubkeys you see in the warning message.
Add the needed repositories:
sudo add-apt-repository 'deb http://httpredir.debian.org/debian experimental main'
sudo add-apt-repository 'deb http://httpredir.debian.org/debian sid main'
Why not use a stable Debian repository? You'll run into unsatisfiable dependencies with Debian stable. The experimental (for openjdk-7) and sid (for libjpeg62-turbo, libfontconfig1, and fontconfig-config) repositories are more lenient with dependency versions.
Update apt
cache (expect this to take a while since Debian's package lists are big):
sudo apt update
Install openjdk-7-jdk:
sudo apt install openjdk-7-jdk
Update java alternatives. You can view all installed java versions with update-java-alternatives --list
. To activate OpenJDK Java 1.7, run:
sudo update-java-alternatives -s java-1.7.0-openjdk-amd64
You may notice an error about the IcedTeaPlugin.so
plugin being unavailable. This isn't a real concern for developers working with the JDK.
Verify java is working:
java -version
which should output something similar to:
java version "1.7.0_161"
OpenJDK Runtime Environment (IcedTea 2.6.12) (7u161-2.6.12-1)
OpenJDK 64-Bit Server VM (build 24.161-b01, mixed mode)
fontconfig notes
libfontconfig1
and fontconfig-config
must be upgraded to 2.12 or later on Ubuntu 17.10 and earlier. The update packages from Debian do not contain Ubuntu's customizations, so some applications display ugly fonts with these packages installed; e.g. Charles Web Debugging Proxy. Depending on the programs you use, you may or may not be affected by this problem.