Ubuntu – How to install openjdk 7 on Ubuntu 16.04 or higher

javaopenjdk

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?

Best Answer

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