134

I would like to upgrade my main system to 16.04, but I work on projects that require OpenJDK 7.

Apparently it is not available from a trivial apt-get install openjdk-7-jdk. Only versions 8 and 9 are listed in the repository.

Can anyone point me to instructions on how to install it?

Anwar
  • 76,649
onairda
  • 3,045

8 Answers8

154

Security Warning

Packages in the PPA mentioned below are not updated with security patches to Java. Do not use in production; see alternative answers instead.

At time of writing, the last upload for OpenJDK 7 was done '2016-04-22' with version 7u95 and still available as 'latest', where Ubuntu 14.04 has been updated to 7u181.


UPDATE : ALTHOUGH THIS IS THE MOST VOTED ANSWER ITS PROBABLY NOT THE ONE YOU WANT TO USE IN 2018 DUE TO LACK OF SECURITY UPDATES BY THIS PPA.

I found the following instructions which worked for me :

sudo add-apt-repository ppa:openjdk-r/ppa  
sudo apt-get update   
sudo apt-get install openjdk-7-jdk  

This defines the “PPA for OpenJDK uploads (restricted)” as an additional package repositiory, updates your information, and installs the package with its dependencies (from that repository).

onairda
  • 3,045
66

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

  1. Download the packages intended for your architecture:
    (for most users, this means amd64 if 64bit, or i386 if 32bit Ubuntu is installed)

  2. (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*
    
  3. 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.

  4. 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.

  5. 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.

  1. 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
    
  2. 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.

  3. 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.

  4. Update apt cache (expect this to take a while since Debian's package lists are big):

    sudo apt update
    
  5. Install openjdk-7-jdk:

    sudo apt install openjdk-7-jdk
    
  6. 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.

  7. 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.

MDMower
  • 850
  • Interesting answer, please update it if you find a way to keep this package automatically updated. – J.Serra Jul 29 '16 at 14:48
  • I just tried installing jdk 7 on ubuntu 16.04 and this is the only way I managed to get it working. Thank you! – link Aug 09 '16 at 06:49
  • 2
    @J.Serra Answer revised with automatic update method. – MDMower Jan 26 '17 at 21:19
  • perfect answered especially the automatic method is highly appreciated! thanks for takin the time to figure out and writing down! – steadfasterX Jul 02 '17 at 08:53
  • 1
    The automatic method mostly worked for me, but is not entirely permanent either. I had to add two more packages to /etc/apt/preferences.d/debian (in addition to libjpeg62-turbo): libfontconfig1 and fontconfig-config – comodoro Aug 27 '17 at 10:31
  • Looks like openjdk-7-jre version 7u151 bumped the version requirement on libfontconfig1 to 2.12 for many platforms (i386 and amd64 included), which in turn requires fontconfig-config >= >= 2.12.3-0.2. Thanks for bringing this to attention and thanks @tim-schumacher for already making the edits to this answer! – MDMower Aug 28 '17 at 14:10
  • Just tried the Automatic method. It gave "openjdk-7-jdk : Depends: openjdk-7-jre (= 7u161-2.6.12-1) E: Unable to correct problems, you have held broken packages.". – John Rose Jan 21 '18 at 18:38
  • @JohnRose can you provide any more info? Your OS? And you copied the entire pinning file, not just a part of it? And verified it saved at the correct location? I just uninstalled OpenJDK 7 and reverted the remaining Debian packages to Ubuntu packages, and then starting over, installation went fine. – MDMower Jan 22 '18 at 03:05
  • Ubuntu 16.04. I did copy the entire pinning file and checked that it was saved at the right location. I subsequently used the manual installation method (i.e. Option 1) and that went Ok , though I did have to do sudo apt install -f to sort out the dependencies ( as instructed in the option). – John Rose Jan 22 '18 at 09:09
  • Thanks for the info @JohnRose . I'm running Ubuntu 17.10, so I'll test on Ubuntu 16.04 tonight and find out if there are additional packages that need to be upgraded. – MDMower Jan 22 '18 at 17:09
  • You are amazing! Tried several other methods for hours and your auto method was the only one that worked (I'm on 18.04). Serious thanks :) – protoEvangelion May 31 '18 at 00:58
  • This method is not working anymore :( I'm at 18.04 – Nam Nguyễn Jul 22 '19 at 05:39
  • Oh, bummer, it looks like Debian removed the experimental JDK packages. I suppose another answer will have to be investigated. I'll make this one as "currently not working". – MDMower Jul 22 '19 at 20:45
  • Maybe, you can consider this where I answered how to install Java 7 or 8 on a more recent Ubuntu. This answer also solves the "PPA DISCONTINUED" Problem. – Cadoiz Aug 31 '21 at 07:34
16

You can download a OpenJDK 7 from Azul which may fit your needs. They both have a DEB (for the package system) and a ZIP distribution. I have only worked with the ZIP distribution.

http://www.azul.com/downloads/zulu/zulu-linux/

7

Use containers

This is a universally valid answer on how to run <outdated> removed software on <current> Ubuntu: containerize your application.

For example, use Docker and an older Ubuntu base image in which the software you're looking for is still available/maintained.

It also works the other way around; try out the software on a newer or even other Linux distribution on your currently running stable Ubuntu.

Example for Java 7 using Ubuntu 14.04

  1. Install Docker - Docker CE free version is fine. See for example https://docs.docker.com/install/linux/docker-ce/ubuntu/ or use the docker.io package in recent Ubuntu versions shipped.

  2. In an empty folder, create a file Dockerfile:

    FROM ubuntu:trusty
    RUN apt-get update \
        && apt-get install -y \
            openjdk-7-jdk \
        && rm -rf /var/lib/apt/lists/*
    
    ENTRYPOINT ["/usr/bin/java"]
    

    Add more packages in that command if you need that.

  3. In that folder, run:

    docker build -t gertvdijk/java7 .
    
  4. Run a command inside a single-use-container using that Java 7 image:

    E.g. java -version:

    docker run --rm -it gertvdijk/java7 -version
    

    Output:

    java version "1.7.0_181"
    OpenJDK Runtime Environment (IcedTea 2.6.14) (7u181-2.6.14-0ubuntu0.1)
    OpenJDK 64-Bit Server VM (build 24.181-b01, mixed mode)
    
  5. Optionally, create a wrapper for convenience.

    • Create a file /usr/local/bin/java7-in-docker with contents:

      #!/usr/bin/env sh -e
      
      DOCKER_IMAGE=gertvdijk/java7
      PWD="$(pwd)"
      
      exec docker run \
        --rm -it \
        -v ${PWD}:${PWD} \
        -v "/etc/passwd:/etc/passwd:ro" \
        -v "/etc/group:/etc/group:ro" \
        --user "$(id -u):$(id -g)" \
        --workdir "${PWD}" \
        "${DOCKER_IMAGE}" \
        $@
      

      This will make the current working directory available inside the container - not your whole filesystem, and it will impersonate your local user account in the container namespace.

    • Mark it as executable:

      sudo chmod +x /usr/local/bin/java7-in-docker
      
  6. Run your Java 7 transparently, like this:

    java7-in-docker -jar relative/path/to/some.jar
    
gertvdijk
  • 67,947
0

An easy way is:

Add these lines to: /etc/apt/sources.list:

deb http://security.ubuntu.com/ubuntu trusty main restricted universe multiverse
deb http://security.ubuntu.com/ubuntu trusty-security main restricted universe multiverse

Then update apt and install. You will probably need to downgrade tzdata package.

After that, I would recommend to comment out those lines and apt update again to prevent install or update of packages from that repository (which could lead to unexpected behavior).

One problem is that you need to hold those packages so they don't get removed when you update your system (specially tzdata package).

NOTE: Use this method as last resort, prefer any other that will allow you to update without issues.

lepe
  • 1,406
0

Install Java 7 on Ubuntu 16.04, Ubuntu 17.04

It’s recommended to install Oracle Java, because it has a performance edge over OpenJDK. For that reason I want to post an alternative. If you want to install Oracle Java run the following commands in terminal to install it from PPA.

  1. Add the needed repositories:

    sudo add-apt-repository ppa:webupd8team/java
    
  2. Update apt cache and install oracle-java7:

    sudo apt update
    sudo apt install java-common oracle-java7-installer
    

    During the installation process you will need to accept the Oracle License agreement. Once installed we need to set Java environment variables such as JAVA_HOME

  3. Correct Java environment variables.

    sudo apt install oracle-java7-set-default
    source /etc/profile
    
  4. Verify java is working:

    java -version
    

    which should output something similar to:

    java version "1.7.0_80"
    Java(TM) SE Runtime Environment (build 1.7.0_80-u80)
    Java HotSpot(TM) 64-Bit Server VM (build 25.131-u80, mixed mode)
    
Teocci
  • 4,665
  • 3
    The oracle installer no longer works Connecting to download.oracle.com (download.oracle.com)|184.51.150.144|:80... connected. HTTP request sent, awaiting response... 404 Not Found – autonomy Aug 15 '17 at 14:53
  • For Oracle JDK, the company is not offering public support for JDK 7 (they offer paid support). I think the apt-get is trying to obtain the installer from a non-existing page. -- If you need JDK 7, you may download installers from Archive website: http://www.oracle.com/technetwork/java/javase/downloads/java-archive-downloads-javase7-521261.html – Jaime Aug 31 '17 at 14:06
0

Oracle JDK alternative:

I wanted to avoid the effort with repositories because I switch between 7, 8, and 9, so I ended up with Oracle JDK rather than OpenJDK. Downloaded from the official site. I am not sure about whether the latest build 80 contains the same fixes as OpenJDK's build 161. But I have it for development so that doesn't mean much anyway to me.

Then you need to set $JAVA_HOME in the environment so that various scripts pick up the right JDK (e.g. Maven, JBoss etc.).

For completeness, JDK version 7 was EOL'ed, even JDK 8 public support is being terminated since September 2017 and will get no public updates after September 2018.

-1

The following worked for me on Ubuntu 18.04

apt-get update && apt-get install default-jdk
Jason
  • 99